﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using CreateLandReport.Context;
using CreateLandReport.Models;
using System.Text.RegularExpressions;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
using CreateLandReport.MyClass;
using static CreateLandReport.Controllers.Land_MaterialController;
using System.Globalization;
using System.Drawing.Drawing2D;

namespace CreateLandReport.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class Land_MaterialController : ControllerBase
    {
        private readonly CoreDbContext _context;
        protected string wtDes = string.Format("五通，即“通路、通电、通讯、给水、排水”");
        protected string ltDes = string.Format("六通，即“通路、通电、通讯、通燃气、给水、排水”");
        protected string qtDes = string.Format("七通，即“通路、通电、通讯、通燃气、给水、排雨水、排污水”");
#if DEBUG
        protected string picPathA = "/home/tdbg/files/";
        protected string picPathProj = "/home/tdbg/proj/";
        protected string modulePath = @"D:\jzdj.doc";
#else
        protected string picPathA = "/home/tdbg/files/";
        protected string picPathProj = "/home/tdbg/proj/";
        protected string modulePath = "/home/tdbg/docm/jzdj.doc";
#endif

        public Land_MaterialController(CoreDbContext context)
        {
            _context = context;
        }

        // GET: api/Land_Material
        [HttpGet]
        public async Task<ActionResult<IEnumerable<Land_Material>>> Getland_material()
        {
          if (_context.land_material == null)
          {
              return NotFound();
          }
            return await _context.land_material.ToListAsync();
        }

        // GET: api/Land_Material/5
        [HttpGet("{id}")]
        public async Task<ActionResult<Land_Material>> GetLand_Material(int id)
        {
          if (_context.land_material == null)
          {
              return NotFound();
          }
            var land_Material = await _context.land_material.FindAsync(id);

            if (land_Material == null)
            {
                return NotFound();
            }

            return land_Material;
        }

        // PUT: api/Land_Material/5
        // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
        [HttpPut("{id}")]
        public async Task<IActionResult> PutLand_Material(int id, Land_Material land_Material)
        {
            if (id != land_Material.id)
            {
                return BadRequest();
            }

            _context.Entry(land_Material).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Land_MaterialExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return NoContent();
        }

        // POST: api/Land_Material
        // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
        [HttpPost]
        public async Task<ActionResult<Land_Material>> PostLand_Material(Land_Material land_Material)
        {
          if (_context.land_material == null)
          {
              return Problem("Entity set 'CoreDbContext.land_material'  is null.");
          }
            _context.land_material.Add(land_Material);
            await _context.SaveChangesAsync();

            return CreatedAtAction("GetLand_Material", new { id = land_Material.id }, land_Material);
        }

        // DELETE: api/Land_Material/5
        [HttpDelete("{id}")]
        public async Task<IActionResult> DeleteLand_Material(int id)
        {
            if (_context.land_material == null)
            {
                return NotFound();
            }
            var land_Material = await _context.land_material.FindAsync(id);
            if (land_Material == null)
            {
                return NotFound();
            }

            _context.land_material.Remove(land_Material);
            await _context.SaveChangesAsync();

            return NoContent();
        }
        [BindProperties]
        public class ItemDetails
        {
            public int mid { get; set; }

            public int aid { get; set; }

            public int bid { get; set; }

            public int cid { get; set; }

            public double ra_regex { get; set; }//通路修正

            public double fs_regex { get; set; }//货运站修正

            public double highway_regex { get; set; }//高速路口

            public double icd_regex { get; set; }//工业聚集度

            public double mj_regex { get; set; }//面积修正

            public double shape_regex { get; set; }//形状修正

            public double sr_regex { get; set; }//临路修正

            public double src_regex { get; set; }//

            public double zsra_regex { get; set; }

            public double zshighway_regex { get; set; }

            public double zsfs_regex { get; set; }

            public double zsinfra_regex { get; set; }

            public double zsnature_regex { get; set; }

            public double zsicd_regex { get; set; }

            public double zsrr_regex { get; set; }

            //public double zsrl_regex { get; set; }

            public double zssr_regex { get; set; }

            public double zsshape_regex { get; set; }

            public double zsmj_regex { get; set; }

            public double zsal_regex { get; set; }

            public double zsterrain_regex { get; set; }

            public double zssrc_regex { get; set; }

            public double zsplan_regex { get; set; }

            public double? zsrg_regex { get; set; }

            public double? zsqyyd_regex { get; set; }

            public double? zsgkmt_regex { get; set; }

            public string qpdj { get; set; }

            public double cbjt_regex { get; set; }

            public double cbjcss_regex { get; set; }

            public double cbhjzl_regex { get; set; }

            public double cbghys_regex { get; set; }

            public double cbgbtj_regex { get; set; }

            public double cbcyjj_regex { get; set; }

            public double gdzb { get; set; }

            public double ydzb { get; set; }

            public double qtnyzb { get; set; }

            public double jzzbzb { get; set; }

            public double wlyzb { get; set; }
        }
        [HttpPost]
        public async Task<ActionResult<ResultClass>> Caculate(ItemDetails id)
        {
            ResultClass rc = new ResultClass();
            #region 找到素材及三个案例
            Land_Material material = await _context.land_material.FindAsync(id.mid);
            Land_Case caseA = await _context.land_case.FindAsync(id.aid);
            Land_Case caseB = await _context.land_case.FindAsync(id.bid);
            Land_Case caseC = await _context.land_case.FindAsync(id.cid);
            #endregion
            JsonResult mess = new JsonResult(new { Message ="" });
            #region 比较法

            #region 获取项目及所在区域
            Land_Project project = new Land_Project();
            var projects = await _context.land_project.ToListAsync();
            var projectSel = projects.Where(t => t.mid == material.id).ToList() ?? null;
            if (projectSel is null)
            {
                mess = new JsonResult(new { Message = string.Format("Success!") });
                return mess;
            }
            else
                project = projectSel[0];

            DateTime valueDate = project.value_date;
            #endregion

            #region 土地剩余使用年限计算
            DateTime endDate;
            try
            {
                endDate = (DateTime)material.out_year;
            }
            catch (Exception ex)
            {
                mess = new JsonResult(new { Message = string.Format("素材土地使用终止日期为空") });
                return mess;
            }
            double years = (endDate - valueDate).TotalDays / 365.25;
            years = Math.Round(years, 2);//土地剩余使用年限2位小数
            rc.mYearsCount = years;
            #endregion

            #region 交易时间对应价格指数
            var industry_priceindex = await _context.industry_priceindex.ToListAsync();
            int mYear, mQuarter;
            int aYear, aQuarter;
            int bYear, bQuarter;
            int cYear, cQuarter;
            if (material.jy_date is null)
            {
                mess = new JsonResult(new { Message = string.Format("素材交易日期为空") });
                return mess;
            }
            else
            {
                DateTime mDate = project.value_date;
                mYear = mDate.Year;
                mQuarter = ((mDate.Month - 1) / 3) + 1;
            }

            if (caseA.jy_date is null)
            {
                mess = new JsonResult(new { Message = string.Format("案例1交易日期为空") });
                return mess;
            }
            else
            {
                DateTime aDate = (DateTime)caseA.jy_date;
                aYear = aDate.Year;
                aQuarter = ((aDate.Month - 1) / 3) + 1;
            }

            if (caseB.jy_date is null)
            {
                mess = new JsonResult(new { Message = string.Format("案例2交易日期为空") });
                return mess;
            }
            else
            {
                DateTime aDate = (DateTime)caseB.jy_date;
                bYear = aDate.Year;
                bQuarter = ((aDate.Month - 1) / 3) + 1;
            }

            if (caseC.jy_date is null)
            {
                mess = new JsonResult(new { Message = string.Format("案例3交易日期为空") });
                return mess;
            }
            else
            {
                DateTime aDate = (DateTime)caseC.jy_date;
                cYear = aDate.Year;
                cQuarter = ((aDate.Month - 1) / 3) + 1;
            }
            int refIndex = -1;
            double mPriceindex = FindPriceIndex(industry_priceindex, mYear, mQuarter ,ref refIndex);
            double aPriceindex = FindPriceIndex(industry_priceindex, aYear, aQuarter, ref refIndex);
            double bPriceindex = FindPriceIndex(industry_priceindex, bYear, bQuarter, ref refIndex);
            double cPriceindex = FindPriceIndex(industry_priceindex, cYear, cQuarter, ref refIndex);
            rc.mPriceIndex = mPriceindex;
            rc.aPriceIndex = aPriceindex;
            rc.bPriceIndex = bPriceindex;
            rc.cPriceIndex = cPriceindex;
            #endregion

            #region 剩余土地使用年限
            double aaa = Math.Round(1 / Math.Pow(1.054, 24.6),4);
            double mlastRegex = 1.0 - (1.0 / Math.Pow(1.054, years));
            double alastRegex = 1.0 - (1.0 / Math.Pow(1.054, 50));
            double blastRegex = 1.0 - (1.0 / Math.Pow(1.054, 50));
            double clastRegex = 1.0 - (1.0 / Math.Pow(1.054, 50));

            rc.mLastYears = Math.Round(mlastRegex,4);
            rc.aLastYears = Math.Round(alastRegex,4);
            rc.bLastYears = Math.Round(blastRegex,4);
            rc.cLastYears = Math.Round(clastRegex,4);
            #endregion

            #region 道路通达度计算
            string mra_des = material.ra_des ?? "";
            if (mra_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("素材道路通达度描述为空") });
                return mess;
            }
            List<string> strings = new List<string>();
            string[] ra_des = "主干道为主、道路通达性优，主干道与次干道并重、道路通达性较优，次干道为主、道路通达性一般，次干道与支路并重、道路通达性较劣，支路为主、道路通达性劣".Split("，");
            foreach (var item in ra_des)
                strings.Add(item);
            double mra_regex = 100.0;
            rc.mRaRegex = mra_regex;
            int indexM = strings.IndexOf(mra_des);
            string ara_des = caseA.ra_des ?? "";
            if (ara_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例1道路通达度描述为空") });
                return mess;
            }
            int indexA = strings.IndexOf(ara_des);
            double ara_regex = 100.0 + (indexM - indexA) * id.ra_regex * 100.0;
            rc.aRaRegex = ara_regex;
            string bra_des = caseB.ra_des ?? "";
            if (bra_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例2道路通达度描述为空") });
                return mess;
            }
            int indexB = strings.IndexOf(bra_des);
            double bra_regex = 100.0 + (indexM - indexB) * id.ra_regex * 100.0;
            rc.bRaRegex = bra_regex;
            string cra_des = caseC.ra_des ?? "";
            if (cra_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例3道路通达度描述为空") });
                return mess;
            }
            int indexC = strings.IndexOf(cra_des);
            double cra_regex = 100.0 + (indexM - indexC) * id.ra_regex * 100.0;
            rc.cRaRegex = cra_regex;
            #endregion

            #region 火车站货运站距离修正
            int interval = 0;
            string mfs_des = material.fs_des ?? "";
            if (mfs_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("素材距货运火车站距离描述为空") });
                return mess;
            }
            string pattern = @"[^\d\.]"; // 去除非数字和小数点的字符
            double outputM = Convert.ToDouble(Regex.Replace(mfs_des, pattern, ""));

            string afs_des = caseA.fs_des ?? "";
            if (afs_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例1距货运火车站距离描述为空") });
                return mess;
            }
            double outputA = Convert.ToDouble(Regex.Replace(afs_des, pattern, ""));

            string bfs_des = caseB.fs_des ?? "";
            if (bfs_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例2距货运火车站距离描述为空") });
                return mess;
            }
            double outputB = Convert.ToDouble(Regex.Replace(bfs_des, pattern, ""));

            string cfs_des = caseC.fs_des ?? "";
            if (cfs_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例3距货运火车站距离描述为空") });
                return mess;
            }
            double outputC = Convert.ToDouble(Regex.Replace(cfs_des, pattern, ""));

            double mfs_regex = 100.0;
            rc.mFsRegex = mfs_regex;
            double afs_regex = 0.0, bfs_regex = 0.0, cfs_regex = 0.0;
            List<DoubleInterval> intervals = new List<DoubleInterval> {
            new DoubleInterval { Start = 25.0, End = double.MaxValue},
            new DoubleInterval { Start = 20.0, End = 25.0},
            new DoubleInterval { Start = 15.0, End = 20.0},
            new DoubleInterval { Start = 10.0, End = 15.0},
            new DoubleInterval { Start = 0.0, End = 10.0},
            };
            int baseIntervalIndex = FindIntervalIndex(intervals, outputM);
            double intervalMultiplier = intervals.Count;

            int intervalIndexA = FindIntervalIndex(intervals, outputA);
            int intervalIndexB = FindIntervalIndex(intervals, outputB);
            int intervalIndexC = FindIntervalIndex(intervals, outputC);

            if (intervalIndexA != baseIntervalIndex)
                afs_regex = 100.0 + id.fs_regex * (intervalIndexA - baseIntervalIndex) * 100.0;
            else
                afs_regex = 100.0;
            rc.aFsRegex = afs_regex;

            if (intervalIndexB != baseIntervalIndex)
                bfs_regex = 100.0 + id.fs_regex * (intervalIndexB - baseIntervalIndex) * 100.0;
            else
                bfs_regex = 100.0;
            rc.bFsRegex = bfs_regex;

            if (intervalIndexC != baseIntervalIndex)
                cfs_regex = 100.0 + id.fs_regex * (intervalIndexC - baseIntervalIndex) * 100.0;
            else
                cfs_regex = 100.0;
            rc.cFsRegex = cfs_regex;
            #endregion

            #region 城市出口
            double mhighway_regex = 100.0;
            double ahighway_regex = 0.0, bhighway_regex = 0.0, chighway_regex = 0.0;
            intervals = new List<DoubleInterval> {
            new DoubleInterval { Start = 12.0, End = double.MaxValue},
            new DoubleInterval { Start = 8.0, End = 12.0 },
            new DoubleInterval { Start = 5.0, End = 8.0 },
            new DoubleInterval { Start = 3.0, End = 5.0 },
            new DoubleInterval { Start = 0.0, End = 3.0 }
            };

            string mhighway_des = material.highway_des ?? "";
            if (mhighway_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("素材距高速路口描述为空") });
                return mess;
            }
            outputM = Convert.ToDouble(Regex.Replace(mhighway_des, pattern, ""));
            rc.mHighwayRegex = 100.0;
            string ahighway_des = caseA.highway_des ?? "";
            if (ahighway_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例1距高速路口描述为空") });
                return mess;
            }
            outputA = Convert.ToDouble(Regex.Replace(ahighway_des, pattern, ""));

            string bhighway_des = caseB.highway_des ?? "";
            if (bhighway_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例2距高速路口描述为空") });
                return mess;
            }
            outputB = Convert.ToDouble(Regex.Replace(bhighway_des, pattern, ""));

            string chighway_des = caseC.highway_des ?? "";
            if (chighway_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例3距高速路口描述为空") });
                return mess;
            }
            outputC = Convert.ToDouble(Regex.Replace(chighway_des, pattern, ""));

            baseIntervalIndex = FindIntervalIndex(intervals, outputM);
            intervalMultiplier = intervals.Count;
            rc.aHighwayRegex = mhighway_regex;
            intervalIndexA = FindIntervalIndex(intervals, outputA);
            intervalIndexB = FindIntervalIndex(intervals, outputB);
            intervalIndexC = FindIntervalIndex(intervals, outputC);

            if (intervalIndexA != baseIntervalIndex)
                ahighway_regex = 100.0 + id.highway_regex * (intervalIndexA - baseIntervalIndex) * 100.0;
            else
                ahighway_regex = 100.0;
            rc.aHighwayRegex = ahighway_regex;

            if (intervalIndexB != baseIntervalIndex)
                bhighway_regex = 100.0 + id.highway_regex * (intervalIndexB - baseIntervalIndex) * 100.00;
            else
                bhighway_regex = 100.0;
            rc.bHighwayRegex = bhighway_regex;
            if (intervalIndexC != baseIntervalIndex)
                chighway_regex = 100.0 + id.highway_regex * (intervalIndexC - baseIntervalIndex) * 100.0;
            else
                chighway_regex = 100.0;
            rc.cHighwayRegex = chighway_regex;
            #endregion

            #region 产业聚集程度
            List<string> cyjjd = new List<string>();
            string[] spStrings = "工业企业众多，产业集聚度高；工业企业较多，产业集聚度较高；工业企业数量一般，产业集聚度一般；工业企业较少，产业集聚度较低；工业企业少，无产业集聚、产业集聚度低".Split('；');
            for(int i = spStrings.Length - 1; i>= 0; i--)
                cyjjd.Add(spStrings[i]);


            string micd_des = material.icd_des ?? "";
            if (micd_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("素材产业集聚度描述为空") });
                return mess;
            }

            double micd_regex = 100.0;
            rc.mIcdRegex = micd_regex;
            indexM = cyjjd.IndexOf(micd_des);
            string aicd_des = caseA.icd_des ?? "";
            if (aicd_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例1产业集聚度描述为空") });
                return mess;
            }
            indexA = cyjjd.IndexOf(aicd_des);
            double aicd_regex = 100.0 + (indexA - indexM) * id.icd_regex * 100.0;
            rc.aIcdRegex = aicd_regex;
            string bicd_des = caseB.icd_des ?? "";
            if (bicd_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例2产业集聚度描述为空") });
                return mess;
            }
            indexB = cyjjd.IndexOf(bicd_des);
            double bicd_regex = 100.0 + (indexB - indexM) * id.icd_regex * 100.0;
            rc.bIcdRegex = bicd_regex;
            string cicd_des = caseC.icd_des ?? "";
            if (cicd_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例3产业集聚度描述为空") });
                return mess;
            }
            indexC = cyjjd.IndexOf(cicd_des);
            double cicd_regex = 100.0 + (indexC - indexM) * id.icd_regex * 100.0;
            rc.cIcdRegex = cicd_regex;
            #endregion

            #region 面积
            List<string> mjList = new List<string>();
            string[] spStrings1 = "面积适宜、对土地利用有利，面积较适宜、对土地利用较有利，面积一般、对土地利用基本无影响，面积较大或较小、对土地利用较为不利，面积过大或过小、对土地利用不利".Split('，');
            for (int i = spStrings1.Length - 1; i >= 0; i--)
                mjList.Add(spStrings1[i]);

            string marea_des = material.area_des ?? "";
            if (marea_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("素材面积描述为空") });
                return mess;
            }

            double mmj_regex = 100.0;
            rc.mMjRegex = mmj_regex;
            indexM = mjList.IndexOf(marea_des);
            string aarea_des = caseA.area_des ?? "";
            if (aarea_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例1面积描述为空") });
                return mess;
            }
            indexA = mjList.IndexOf(aarea_des);
            double amj_regex = 100.0 + (indexA - indexM) * id.mj_regex * 100.0;
            rc.aMjRegex = amj_regex;
            string barea_des = caseB.area_des ?? "";
            if (barea_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例2面积描述为空") });
                return mess;
            }
            indexB = mjList.IndexOf(barea_des);
            double bmj_regex = 100.0 + (indexB - indexM) * id.mj_regex * 100.0;
            rc.bMjRegex = bmj_regex;
            string carea_des = caseC.area_des ?? "";
            if (carea_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例3面积描述为空") });
                return mess;
            }
            indexC = mjList.IndexOf(carea_des);
            double cmj_regex = 100.0 + (indexC - indexM) * id.mj_regex * 100.0;
            rc.cMjRegex = cmj_regex;
            #endregion

            #region 形状
            List<string> xzList = new List<string>();
            string[] spStrings2 = "规则、对土地利用有利，较规则、对土地利用较有利，基本规则、对土地利用基本无影响，较不规则、对土地利用有一定不利影响，不规则、对土地利用影响".Split('，');
            for (int i = spStrings2.Length - 1; i >= 0; i--)
                xzList.Add(spStrings2[i]);

            string mshape_des = material.shape_des ?? "";
            if (mshape_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("素材形状描述为空") });
                return mess;
            }

            double mshape_regex = 100.0;
            rc.mShapeRegex = mshape_regex;
            indexM = xzList.IndexOf(mshape_des);
            string ashape_des = caseA.shape_des ?? "";
            if (ashape_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例1形状描述为空") });
                return mess;
            }
            indexA = xzList.IndexOf(ashape_des);
            double ashape_regex = 100.0 + (indexA - indexM) * id.shape_regex * 100.0;
            rc.aShapeRegex = ashape_regex;
            string bshape_des = caseB.shape_des ?? "";
            if (bshape_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例2形状描述为空") });
                return mess;
            }
            indexB = xzList.IndexOf(bshape_des);
            double bshape_regex = 100.0 + (indexB - indexM) * id.shape_regex * 100.0;
            rc.bShapeRegex = bshape_regex;
            string cshape_des = caseC.shape_des ?? "";
            if (cshape_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例3形状描述为空") });
                return mess;
            }
            indexC = xzList.IndexOf(cshape_des);
            double cshape_regex = 100.0 + (indexC - indexM) * id.shape_regex * 100.0;
            rc.cShapeRegex = cshape_regex;
            #endregion

            #region 临路类型
            List<string> lllxList = new List<string>();
            string[] spStrings3 = "临交通型主干道、临混合型主干道、临生活型主干道或交通型次干道、临生活型次干道、临支路".Split('、');
            for (int i = spStrings3.Length - 1; i >= 0; i--)
                lllxList.Add(spStrings3[i]);

            string msr_des = material.sr_des ?? "";
            if (msr_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("素材临路描述为空") });
                return mess;
            }

            double msr_regex = 100.0;
            rc.mSrRegex = msr_regex;
            indexM = lllxList.IndexOf(msr_des);
            string asr_des = caseA.sr_des ?? "";
            if (asr_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例1临路描述为空") });
                return mess;
            }
            indexA = lllxList.IndexOf(asr_des);
            double asr_regex = 100.0 + (indexA - indexM) * id.sr_regex * 100.0;
            rc.aSrRegex = asr_regex;
            string bsr_des = caseB.sr_des ?? "";
            if (bsr_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例2临路描述为空") });
                return mess;
            }
            indexB = lllxList.IndexOf(bsr_des);
            double bsr_regex = 100.0 + (indexB - indexM) * id.sr_regex * 100.0;
            rc.bSrRegex = bsr_regex;
            string csr_des = caseC.sr_des ?? "";
            if (csr_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例3临路描述为空") });
                return mess;
            }
            indexC = lllxList.IndexOf(csr_des);
            double csr_regex = 100.0 + (indexC - indexM) * id.sr_regex * 100.0;
            rc.cSrRegex = csr_regex;
            #endregion

            #region 临路状况
            List<string> llzkList = new List<string>();
            string[] spStrings4 = "四面临路、三面临路、二面临路、一面临路、不直接临路".Split('、');
            for (int i = spStrings4.Length - 1; i >= 0; i--)
                llzkList.Add(spStrings4[i]);

            string msrc_des = material.src_des ?? "";
            if (msrc_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("素材临路状况描述为空") });
                return mess;
            }

            double msrc_regex = 100.0;
            rc.mSrcRegex = msrc_regex;
            indexM = llzkList.IndexOf(msrc_des);
            string asrc_des = caseA.src_des ?? "";
            if (asrc_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例1临路状况描述为空") });
                return mess;
            }
            indexA = llzkList.IndexOf(asrc_des);
            double asrc_regex = 100.0 + (indexA - indexM) * id.src_regex * 100.0;
            rc.aSrcRegex = asrc_regex;
            string bsrc_des = caseB.src_des ?? "";
            if (bsrc_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例2临路状况描述为空") });
                return mess;
            }
            indexB = llzkList.IndexOf(bsrc_des);
            double bsrc_regex = 100.0 + (indexB - indexM) * id.src_regex * 100.0;
            rc.bSrcRegex = bsrc_regex;
            string csrc_des = caseC.src_des ?? "";
            if (csrc_des.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("案例3临路状况描述为空") });
                return mess;
            }
            indexC = llzkList.IndexOf(csrc_des);
            double csrc_regex = 100.0 + (indexC - indexM) * id.src_regex * 100.0;
            rc.cSrcRegex = csrc_regex;
            #endregion

            #region 计算
            double jyRegexA = 1.0;
            double jyRegexB = 1.0;
            double jyRegexC = 1.0;

            double jyrqRegexA = Math.Round(mPriceindex / aPriceindex, 4);
            double jyrqRegexB = Math.Round(mPriceindex / bPriceindex, 4);
            double jyrqRegexC = Math.Round(mPriceindex / cPriceindex, 4);

            double ytRegexA = 1.0;
            double ytRegexB = 1.0;
            double ytRegexC = 1.0;

            double jyfsRegexA = 1.0;
            double jyfsRegexB = 1.0;
            double jyfsRegexC = 1.0;

            double synxRegexA = Math.Round(mlastRegex / alastRegex, 4);
            double synxRegexB = Math.Round(mlastRegex / blastRegex, 4);
            double synxRegexC = Math.Round(mlastRegex / clastRegex, 4);

            double dltdRegexA = 100.0 / ara_regex;
            double dltdRegexB = 100.0 / bra_regex;
            double dltdRegexC = 100.0 / cra_regex;

            double hyhcRegexA = 100.0 / afs_regex;
            double hyhcRegexB = 100.0 / bfs_regex;
            double hyhcRegexC = 100.0 / cfs_regex;

            double csckRegexA = 100.0 / ahighway_regex;
            double csckRegexB = 100.0 / bhighway_regex;
            double csckRegexC = 100.0 / chighway_regex;

            double jtgzRegexA = 1.0;
            double jtgzRegexB = 1.0;
            double jtgzRegexC = 1.0;

            double jcssRegexA = 1.0;
            double jcssRegexB = 1.0;
            double jcssRegexC = 1.0;

            double cyjjRegexA = 100.0 / aicd_regex;
            double cyjjRegexB = 100.0 / aicd_regex;
            double cyjjRegexC = 100.0 / aicd_regex;

            double hjzkRegexA = 1.0;
            double hjzkRegexB = 1.0;
            double hjzkRegexC = 1.0;

            double ydghRegexA = 1.0;
            double ydghRegexB = 1.0;
            double ydghRegexC = 1.0;

            double mjRegexA = 100.0 / amj_regex;
            double mjRegexB = 100.0 / bmj_regex;
            double mjRegexC = 100.0 / cmj_regex;

            double xzRegexA = 100.0 / ashape_regex;
            double xzRegexB = 100.0 / bshape_regex;
            double xzRegexC = 100.0 / cshape_regex;

            double llRegexA = 100.0 / asr_regex;
            double llRegexB = 100.0 / bsr_regex;
            double llRegexC = 100.0 / csr_regex;

            double llzkRegexA = 100.0 / asrc_regex;
            double llzkRegexB = 100.0 / bsrc_regex;
            double llzkRegexC = 100.0 / csrc_regex;

            double dxzsRegexA = 1.0;
            double dxzsRegexB = 1.0;
            double dxzsRegexC = 1.0;

            double dzRegexA = 1.0;
            double dzRegexB = 1.0;
            double dzRegexC = 1.0;

            double zwydRegexA = 1.0;
            double zwydRegexB = 1.0;
            double zwydRegexC = 1.0;

            double ghxzRegexA = 1.0;
            double ghxzRegexB = 1.0;
            double ghxzRegexC = 1.0;

            double rjlRegexA = 1.0;
            double rjlRegexB = 1.0;
            double rjlRegexC = 1.0;

            double totalRegexA = jyRegexA * jyrqRegexA * ytRegexA * jyfsRegexA * synxRegexA * dltdRegexA * hyhcRegexA *
                csckRegexA * jtgzRegexA * jcssRegexA * cyjjRegexA * hjzkRegexA * ydghRegexA * mjRegexA * xzRegexA *
                llRegexA * llRegexA * llzkRegexA * dxzsRegexA * dzRegexA * zwydRegexA * ghxzRegexA * rjlRegexA;
            rc.totalRegexA = totalRegexA;

            double totalRegexB = jyRegexB * jyrqRegexB * ytRegexB * jyfsRegexB * synxRegexB * dltdRegexB * hyhcRegexB *
                csckRegexB * jtgzRegexB * jcssRegexB * cyjjRegexB * hjzkRegexB * ydghRegexB * mjRegexB * xzRegexB *
                llRegexB * llRegexB * llzkRegexB * dxzsRegexB * dzRegexB * zwydRegexB * ghxzRegexB * rjlRegexB;
            rc.totalRegexB = totalRegexB;

            double totalRegexC = jyRegexC * jyrqRegexC * ytRegexC * jyfsRegexC * synxRegexC * dltdRegexC * hyhcRegexC *
               csckRegexC * jtgzRegexC * jcssRegexC * cyjjRegexC * hjzkRegexC * ydghRegexC * mjRegexC * xzRegexC *
               llRegexC * llRegexC * llzkRegexC * dxzsRegexC * dzRegexC * zwydRegexC * ghxzRegexC * rjlRegexC;
            rc.totalRegexC = totalRegexC;
            if (caseA.land_money is null)
            {
                mess = new JsonResult(new { Message = string.Format("案例1价格为空") });
                return mess;
            }
            double priceA = Math.Round((int)caseA.land_money * totalRegexA, 2);

            if (caseB.land_money is null)
            {
                mess = new JsonResult(new { Message = string.Format("案例2价格为空") });
                return mess;
            }
            double priceB = Math.Round((int)caseB.land_money * totalRegexB, 2);

            if (caseC.land_money is null)
            {
                mess = new JsonResult(new { Message = string.Format("案例3价格为空") });
                return mess;
            }
            double priceC = Math.Round((int)caseC.land_money * totalRegexC, 2);

            int priceEE = Convert.ToInt32((priceA + priceB + priceC)/3);
            #endregion
            rc.bjPrice = priceEE;

            #endregion

            #region 基准地价
            double testA = id.zsqyyd_regex ?? 0.0;
            double testB = id.zsgkmt_regex ?? 0.0;
            double testC = id.zsrg_regex ?? 0.0;
            double regesJZDXE = id.zsra_regex + id.zshighway_regex + id.zsfs_regex + id.zsinfra_regex + id.zsnature_regex + id.zsicd_regex +
               id.zsrr_regex /*+ id.zsrl_regex*/ + id.zssr_regex + id.zsshape_regex + id.zsmj_regex + id.zsal_regex +
                id.zsterrain_regex + id.zsplan_regex + id.zssrc_regex + testA + testB + testC;
            rc.regesJZDXE = Math.Round(regesJZDXE * 100.0,2).ToString();
            string region = material.regin ?? "";
            if(region.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("素材所在区域为空!") });
                return mess;
            }

            var listRR = await _context.rr_price.ToListAsync();
            var zdItem = listRR.Where(t => t.region_name == region).ToList()[0];
            int totalP = zdItem.t_price;
            string infra_desM = material.infra_des ?? "";
            int priceMin = 0;
            if(infra_desM.Length == 0)
            {
                mess = new JsonResult(new { Message = string.Format("素材基础设施完善度为空!") });
                return mess;
            }
            if(infra_desM.Contains("五通"))
            {
                priceMin = 257 - totalP;
            }
            else if (infra_desM.Contains("六通"))
            {
                priceMin = 297 - totalP;
            }
            else//不明
            {
                priceMin = 257 - totalP;
            }
            rc.infraPrice = priceMin;
            var lisDoc = await _context.guidance_document.ToListAsync();
            var docItem = lisDoc.Where(t => t.region_name == region).ToList()[0];
            DateTime fbDate = docItem.announcement_date;

            int docYear = fbDate.Year;
            int docQuarter = ((fbDate.Month - 1) / 3) + 1;
            refIndex = -1;

            double fbPriceindex = FindPriceIndex(industry_priceindex, docYear, docQuarter, ref refIndex);

            double k2Regex = (1 - 1/Math.Pow(1 + 0.054,years)) / (1 - 1 / Math.Pow(1 + 0.054, 50));
            rc.k2Regex = k2Regex;
            double k3Regex = mPriceindex/ fbPriceindex;
            rc.k3Regex = k3Regex;
            if(material.land_money is null)
            {
                mess = new JsonResult(new { Message = string.Format("素材地价为空!") });
                return mess;
            }
            double zsPrice2 = Math.Round((int)material.land_money * (1 + regesJZDXE) * 1.0 * k2Regex * k3Regex + priceMin, 2);
            rc.zsPrice2 = zsPrice2;
            int priceZS = Convert.ToInt32(zsPrice2);
            rc.zsPrice = priceZS;
            #endregion

            #region 成本逼近
            double totalPercent = id.gdzb + id.ydzb + id.qtnyzb + id.jzzbzb + id.wlyzb;//耕地占比+园地占比+其他用地占比+建筑用地占比+未利用地占比
            if (totalPercent != 1.0)//求和必须为100%
            {
                if(totalPercent > 1.0)
                {
                    mess = new JsonResult(new { Message = string.Format("成本逼近法中耕地等占比相加大于100%") });
                    return mess;
                }
                else
                {
                    mess = new JsonResult(new { Message = string.Format("成本逼近法中耕地等占比相加小于100%") });
                    return mess;
                }
            }
            else
            {
                var cbList = await _context.cbbj_database.ToListAsync();//获取成本逼近表的数据
                Cbbj_Database cbItem = cbList.Where(t => t.region_name == region && t.region_level == id.qpdj).ToList()[0];//根据区域及前端传入等级获取成本逼近obj

                double bcPrice = cbItem.tdbc_price;//获取补偿价格
                double jzPrice = bcPrice * 0.7;//计算建筑用地补偿价格
                int tdbcPrice = Convert.ToInt32(bcPrice * (id.gdzb + id.ydzb + id.qtnyzb + id.jzzbzb) + jzPrice * id.wlyzb);//根据占比计算土地补偿总价
                double re = ((id.gdzb + id.ydzb + id.qtnyzb) / cbItem.rjnyd) * cbItem.azbc_price;//安置补偿总价计算
                int azbzPricr = Convert.ToInt32(re);//安置补偿总价取整
                int qmbzPric = Convert.ToInt32((id.gdzb + id.ydzb + id.qtnyzb) * cbItem.qmbc_price);//青苗补偿总价取整
                int fzwPrice = Convert.ToInt32(cbItem.dsfs_price);//地上附属物价格取整
                int nykfPrice = Convert.ToInt32((id.gdzb + id.ydzb + id.qtnyzb) * cbItem.kfjs_price);//农业开发费用计算取整
                int gdkkPrice = Convert.ToInt32((id.gdzb + id.ydzb + id.qtnyzb) * cbItem.gdkk_price);//耕地开垦费用计算取整
                int gdzyPrice = Convert.ToInt32((id.gdzb + id.ydzb + id.qtnyzb) * cbItem.gdzy_price);//耕地征用费用计算取整
                
                int totalPrice = Convert.ToInt32((tdbcPrice + azbzPricr + qmbzPric + fzwPrice + nykfPrice + gdkkPrice + gdzyPrice) / 666.6667);//总价从亩转为平米
                //以上对应表13
                int jcssPrice = totalP;//对应区域几通一平价格
                var a = (totalPrice + jcssPrice - 10.0);
                var b = Math.Pow(1 + 0.0435, 1) - 1;
                var c = Math.Pow(1 + 0.0435, 0.5);
                re = a * b + 10.0 * (c - 1.0);
                double lxPercent = Math.Round(re, 2);//利息计算
                double lrlPercent = (totalPrice + jcssPrice) * cbItem.tzlr_percent;//利润率计算
                double tdzzlPercent = (totalPrice + jcssPrice + lxPercent + lrlPercent) * cbItem.tdzz_percent;//土地增值收益计算
                double tdhyPercent = 1.0 - (1.0 / Math.Pow(1 + cbItem.tdhy_percent, years));//土地还原率计算
                double eChangeSum = id.cbjt_regex + id.cbjcss_regex + id.cbhjzl_regex + id.cbghys_regex + id.cbgbtj_regex + id.cbcyjj_regex;//前端传入各修正参数求和
                re = (totalPrice + jcssPrice + lxPercent + lrlPercent + tdzzlPercent) * tdhyPercent * (1 + eChangeSum);//单价计算
                int cbPrice = Convert.ToInt32(re);//单价计算取整
                rc.cbPrice = cbPrice;
            }
            #endregion
            return rc;
        }

        [BindProperties]
        public class Item
        {
            public ItemDetails itemDetails { get; set; }
            public ResultClass resultClass { get; set; }
        }
        [HttpPost]
        public async Task<ActionResult> CreateFile(Item item)
        {
            ItemDetails details = item.itemDetails;
            ResultClass resultClass = item.resultClass;
            JsonResult mess = new JsonResult(new { Message = "" });
            Dictionary<string, string> replaceDic = new Dictionary<string, string>();
            List<ImageDetails> imageDetails = new List<ImageDetails>();
            List<Guidance_Document> guidanceDocuments = await _context.guidance_document.ToListAsync();
            List<Coblp> coblps = await _context.coblp.ToListAsync();
            List<Appraiser> appraiser = await _context.appraiser.ToListAsync();
            List<Industry_Priceindex> industryPriceindices = await _context.industry_priceindex.ToListAsync();
            List<Gs_Ccoblp> gs_Ccoblps = await _context.gs_ccoblp.ToListAsync();
            List<Wz_Ccoblp> wz_Ccoblps = await _context.wz_ccoblp.ToListAsync();
            List<Xc_Ccoblp> xc_Ccoblps = await _context.xc_ccoblp.ToListAsync();
            List<Rr_Price> listRR = await _context.rr_price.ToListAsync();
            
            #region 找到素材及三个案例、项目
            Land_Material material = await _context.land_material.FindAsync(details.mid);
            Land_Case caseA = await _context.land_case.FindAsync(details.aid);
            Land_Case caseB = await _context.land_case.FindAsync(details.bid);
            Land_Case caseC = await _context.land_case.FindAsync(details.cid);
            Guidance_Document guidanceDocument = guidanceDocuments.Where(t => t.region_name == material.regin).ToList()[0];

            Coblp coblp = new Coblp();
            if(material.regin != "吴中区" && material.regin != "相城区")
                coblp = coblps.Where(t => t.region_name == "市区" 
                && t.usetype == material.usages 
                && t.level == material.use_level).ToList()[0];
            else
                coblp = coblps.Where(t => t.region_name == material.regin
                && t.usetype == material.usages
                && t.level == material.use_level).ToList()[0];

            Rr_Price rr_item = listRR.Where(t => t.region_name == material.regin).ToList()[0];
            Land_Project project = new Land_Project();
            var projects = await _context.land_project.ToListAsync();
            var projectSel = projects.Where(t => t.mid == material.id).ToList() ?? null;
            if (projectSel is null)
            {
                mess = new JsonResult(new { Message = string.Format("无法找到素材对项目或找不到项目对应素材") });
                return mess;
            }
            else
                project = projectSel[0];

            if (material.regin != "吴中区")
            {
                if(material.regin == "相城区")
                {
                    var xcCCCs = xc_Ccoblps.Where(t => t.use_levela == material.use_level).ToList();
                    foreach(var xc in xcCCCs)
                    {
                        string eff_c = xc.eff_condia;
                        switch(eff_c)
                        {
                            case "优":
                                replaceDic.Add("#tra1#", xc.ra_desa);
                                replaceDic.Add("#thw1#", xc.highway_desa);
                                replaceDic.Add("#tfs1#", xc.fs_desa);
                                replaceDic.Add("#tpt1#", xc.highway_desa);
                                replaceDic.Add("#tbz1#", "——");

                                replaceDic.Add("#ttra1#", Math.Round(xc.ra_ratea * 100.0,2).ToString("F2"));
                                replaceDic.Add("#tthw1#", Math.Round(xc.highway_ratea * 100.0,2).ToString("F2"));
                                replaceDic.Add("#ttfs1#", Math.Round(xc.fs_ratea * 100.0,2).ToString("F2"));
                                replaceDic.Add("#ttgk1#", Math.Round(xc.port_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttjc1#", Math.Round(xc.infra_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttzr1#", Math.Round(xc.nature_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttjj1#", Math.Round(xc.icd_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttdl1#", Math.Round(xc.rr_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttgh1#", Math.Round(xc.icd_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttbz1#%", "——");
                                replaceDic.Add("#ttdl1#", Math.Round(xc.rl_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttlj1#", Math.Round(xc.sr_typea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttlt1#", Math.Round(xc.sr_condia * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttxz1#", Math.Round(xc.land_shapea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttmj1#", Math.Round(xc.land_areaa * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttzy1#", Math.Round(xc.al_typea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttds1#", Math.Round(xc.terrain_condia * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttgx1#", Math.Round(xc.plan_limita * 100.0, 2).ToString("F2"));
                                break;
                            case "较优":
                                replaceDic.Add("#tra2#", xc.ra_desa);
                                replaceDic.Add("#thw2#", xc.highway_desa);
                                replaceDic.Add("#tfs2#", xc.fs_desa);
                                replaceDic.Add("#tpt2#", xc.highway_desa);
                                replaceDic.Add("#tbz2#", "——");

                                replaceDic.Add("#ttra2#", Math.Round(xc.ra_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#tthw2#", Math.Round(xc.highway_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttfs2#", Math.Round(xc.fs_ratea * 100.0,2).ToString("F2"));
                                replaceDic.Add("#ttgk2#", Math.Round(xc.port_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttjc2#", Math.Round(xc.infra_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttzr2#", Math.Round(xc.nature_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttjj2#", Math.Round(xc.icd_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttdl2#", Math.Round(xc.rr_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttgh2#", Math.Round(xc.icd_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttbz2#%", "——");
                                replaceDic.Add("#ttdl2#", Math.Round(xc.rl_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttlj2#", Math.Round(xc.sr_typea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttlt2#", Math.Round(xc.sr_condia * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttxz2#", Math.Round(xc.land_shapea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttmj2#", Math.Round(xc.land_areaa * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttzy2#", Math.Round(xc.al_typea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttds2#", Math.Round(xc.terrain_condia * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttgx2#", Math.Round(xc.plan_limita * 100.0, 2).ToString("F2"));
                                break;
                            case "一般":
                                replaceDic.Add("#tra3#", xc.ra_desa);
                                replaceDic.Add("#thw3#", xc.highway_desa);
                                replaceDic.Add("#tfs3#", xc.fs_desa);
                                replaceDic.Add("#tpt3#", xc.highway_desa);
                                replaceDic.Add("#tbz3#", "——");
                                replaceDic.Add("#ttbz5#%", "——");
                                replaceDic.Add("#ttgk5#%", "0.00%");
                                break;
                            case "较劣":
                                replaceDic.Add("#tra4#", xc.ra_desa);
                                replaceDic.Add("#thw4#", xc.highway_desa);
                                replaceDic.Add("#tfs4#", xc.fs_desa);
                                replaceDic.Add("#tpt4#", xc.highway_desa);
                                replaceDic.Add("#tbz4#", "——");

                                replaceDic.Add("#ttra3#", Math.Round(xc.ra_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#tthw3#", Math.Round(xc.highway_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttfs3#", Math.Round(xc.fs_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttgk3#", Math.Round(xc.port_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttjc3#", Math.Round(xc.infra_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttzr3#", Math.Round(xc.nature_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttjj3#", Math.Round(xc.icd_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttdl3#", Math.Round(xc.rr_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttgh3#", Math.Round(xc.icd_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttbz3#%", "——");
                                replaceDic.Add("#ttdl3#", Math.Round(xc.rl_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttlj3#", Math.Round(xc.sr_typea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttlt3#", Math.Round(xc.sr_condia * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttxz3#", Math.Round(xc.land_shapea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttmj3#", Math.Round(xc.land_areaa * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttzy3#", Math.Round(xc.al_typea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttds3#", Math.Round(xc.terrain_condia * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttgx3#", Math.Round(xc.plan_limita * 100.0, 2).ToString("F2"));
                                break;
                            case "劣":
                                replaceDic.Add("#tra5#", xc.ra_desa);
                                replaceDic.Add("#thw5#", xc.highway_desa);
                                replaceDic.Add("#tfs5#", xc.fs_desa);
                                replaceDic.Add("#tpt5#", xc.highway_desa);
                                replaceDic.Add("#tbz5#", "——");

                                replaceDic.Add("#ttra4#", Math.Round(xc.ra_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#tthw4#", Math.Round(xc.highway_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttfs4#", Math.Round(xc.fs_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttgk4#", Math.Round(xc.port_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttjc4#", Math.Round(xc.infra_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttzr4#", Math.Round(xc.nature_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttjj4#", Math.Round(xc.icd_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttdl4#", Math.Round(xc.rr_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttgh4#", Math.Round(xc.icd_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttbz4#%", "——");
                                replaceDic.Add("#ttdl4#", Math.Round(xc.rl_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttlj4#", Math.Round(xc.sr_typea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttlt4#", Math.Round(xc.sr_condia * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttxz4#", Math.Round(xc.land_shapea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttmj4#", Math.Round(xc.land_areaa * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttzy4#", Math.Round(xc.al_typea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttds4#", Math.Round(xc.terrain_condia * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttgx4#", Math.Round(xc.plan_limita * 100.0, 2  ).ToString("F2"));
                                break;
                            default:
                                break;
                        }
                    }

                    var cclopaa = coblps.Where(t => t.region_name == "市区" && t.usetype == "商服").OrderBy(t => t.level).ToList();
                    replaceDic.Add("#SF_D#", cclopaa[0].price_define);
                    replaceDic.Add("#KFCDS#", cclopaa[0].ld_rate);
                    int cout = 1;
                    for (int i = 0; i < cclopaa.Count; i++)
                    {
                        replaceDic.Add(string.Format("#SP{0}#", cout), cclopaa[i].plot_ratio.ToString());
                        cout += 1;
                    }
                    if (cout < 7)
                    {
                        for (int i = cout; cout < 7; cout++)
                            replaceDic.Add(string.Format("#SP{0}#", cout), "");
                    }


                    cout = 1;
                    cclopaa = coblps.Where(t => t.region_name == "相城区" && t.usetype == "住宅").OrderBy(t => t.level).ToList();
                    replaceDic.Add("#住宅R#", "住宅");
                    replaceDic.Add("#ZZ_D#", cclopaa[0].price_define);
                    replaceDic.Add("#KFCDZ#", cclopaa[0].ld_rate);
                    for (int i = 0; i < cclopaa.Count; i++)
                    {
                        replaceDic.Add(string.Format("#ZP{0}#", cout), cclopaa[i].plot_ratio.ToString());
                        cout += 1;
                    }
                    if (cout < 7)
                    {
                        for (int i = cout; cout < 7; cout++)
                            replaceDic.Add(string.Format("#ZP{0}#", cout), "");
                    }

                    cout = 1;
                    cclopaa = coblps.Where(t => t.region_name == "相城区" && t.usetype == "工业").OrderBy(t => t.level).ToList();
                    //replaceDic.Add("#住宅R#", "住宅");
                    replaceDic.Add("#GY_D#", cclopaa[0].price_define);
                    replaceDic.Add("#KFCDG#", cclopaa[0].ld_rate);
                    for (int i = 0; i < cclopaa.Count; i++)
                    {
                        replaceDic.Add(string.Format("#GP{0}#", cout), cclopaa[i].plot_ratio.ToString());
                        cout += 1;
                    }
                    if (cout < 7)
                    {
                        for (int i = cout; cout < 7; cout++)
                            replaceDic.Add(string.Format("#GP{0}#", cout), "");
                    }

                    cout = 1;
                    cclopaa = coblps.Where(t => t.region_name == "相城区" && t.usetype == "公服").OrderBy(t => t.level).ToList();
                    replaceDic.Add("#公服R#", "公服");
                    replaceDic.Add("#GF_D#", cclopaa[0].price_define);
                    replaceDic.Add("#KFCDGF#", cclopaa[0].ld_rate);
                    for (int i = 0; i < cclopaa.Count; i++)
                    {
                        replaceDic.Add(string.Format("#GF{0}#", cout), cclopaa[i].plot_ratio.ToString());
                        cout += 1;
                    }
                    if (cout < 7)
                    {
                        for (int i = cout; cout < 7; cout++)
                            replaceDic.Add(string.Format("#GF{0}#", cout), "");
                    }

                    var selItemXc = xc_Ccoblps.Where(t => t.ra_ratea == details.zsra_regex).First().ra_desa;
                    replaceDic.Add("#ra_desa#", selItemXc);
                    replaceDic.Add("#ra_ratea#", Math.Round(details.zsra_regex * 100.0,2).ToString());

                    selItemXc = xc_Ccoblps.Where(t => t.highway_ratea == details.zshighway_regex).First().highway_desa;
                    replaceDic.Add("#highway_desa#", selItemXc);
                    replaceDic.Add("#highway_ratea#", Math.Round(details.zshighway_regex * 100.0, 2).ToString());

                    selItemXc = xc_Ccoblps.Where(t => t.fs_ratea == details.zsfs_regex).First().fs_desa;
                    replaceDic.Add("#fs_desa#", selItemXc);
                    replaceDic.Add("#fs_ratea#", Math.Round(details.zsfs_regex * 100.0, 2).ToString());

                    double gkmt = details.zsgkmt_regex ?? 0.0;
                    selItemXc = xc_Ccoblps.Where(t => t.port_ratea == gkmt).First().fs_desa;
                    replaceDic.Add("#port_desa#", selItemXc);
                    replaceDic.Add("#port_ratea#", Math.Round(gkmt * 100.0, 2).ToString());

                    selItemXc = xc_Ccoblps.Where(t => t.infra_ratea == details.zsinfra_regex).First().infra_desa;
                    replaceDic.Add("#infra_desa#", selItemXc);
                    replaceDic.Add("#infra_ratea#", Math.Round(details.zsinfra_regex * 100.0, 2).ToString());

                    selItemXc = xc_Ccoblps.Where(t => t.nature_ratea == details.zsnature_regex).First().nature_desa;
                    replaceDic.Add("#nature_desa#", selItemXc);
                    replaceDic.Add("#nature_ratea#", Math.Round(details.zsnature_regex * 100.0, 2).ToString());

                    selItemXc = xc_Ccoblps.Where(t => t.icd_ratea == details.zsicd_regex).First().icd_desa;
                    replaceDic.Add("#icd_desa#", selItemXc);
                    replaceDic.Add("#icd_ratea#", Math.Round(details.zsicd_regex * 100.0, 2).ToString());

                    selItemXc = xc_Ccoblps.Where(t => t.rr_ratea == details.zsrr_regex).First().rr_desa;
                    replaceDic.Add("#rr_desa#", selItemXc);
                    replaceDic.Add("#rr_ratea#", Math.Round(details.zsrr_regex * 100.0, 2).ToString());

                    double qyyd = details.zsqyyd_regex ?? 0.0;
                    selItemXc = xc_Ccoblps.Where(t => t.rl_ratea == qyyd).First().rl_desa;
                    replaceDic.Add("#rl_desa#", selItemXc);
                    replaceDic.Add("#rl_ratea#", Math.Round(qyyd * 100.0, 2).ToString());

                    replaceDic.Add("#rg_desa#", "——");
                    replaceDic.Add("#rg_ratea#%", "——");

                    selItemXc = xc_Ccoblps.Where(t => t.sr_typea == details.zssr_regex).First().sr_desa;
                    replaceDic.Add("#sr_desa#", selItemXc);
                    replaceDic.Add("#sr_ratea#", Math.Round(details.zssr_regex * 100.0, 2).ToString());

                    selItemXc = xc_Ccoblps.Where(t => t.sr_condia == details.zssrc_regex).First().src_desa;
                    replaceDic.Add("#src_desa#", selItemXc);
                    replaceDic.Add("#src_ratea#", Math.Round(details.zssrc_regex * 100.0, 2).ToString());

                    selItemXc = xc_Ccoblps.Where(t => t.land_shapea == details.zsshape_regex).First().shape_desa;
                    replaceDic.Add("#shape_desa#", selItemXc);
                    replaceDic.Add("#shape_ratea#", Math.Round(details.zsshape_regex * 100.0, 2).ToString());

                    selItemXc = xc_Ccoblps.Where(t => t.land_areaa == details.mj_regex).First().area_desa;
                    replaceDic.Add("#area_desa#", selItemXc);
                    replaceDic.Add("#area_ratea#", Math.Round(details.zsmj_regex * 100.0, 2).ToString());

                    selItemXc = xc_Ccoblps.Where(t => t.al_typea == details.zsal_regex).First().al_desa;
                    replaceDic.Add("#al_desa#", selItemXc);
                    replaceDic.Add("#al_ratea#", Math.Round(details.zsal_regex * 100.0, 2).ToString());

                    selItemXc = xc_Ccoblps.Where(t => t.terrain_condia == details.zsterrain_regex).First().terrain_desa;
                    replaceDic.Add("#errain_desa#", selItemXc);
                    replaceDic.Add("#errain_ratea#", Math.Round(details.zsal_regex * 100.0, 2).ToString());

                    selItemXc = xc_Ccoblps.Where(t => t.plan_limita == details.zsplan_regex).First().plan_desa;
                    replaceDic.Add("#plan_desa#", selItemXc);
                    replaceDic.Add("#plan_ratea#", Math.Round(details.zsplan_regex * 100.0, 2).ToString());
                }
                else
                {
                    var gsCCCs = gs_Ccoblps.Where(t => t.use_levela == material.use_level).ToList();
                    foreach (var gs in gsCCCs)
                    {
                        string eff_c = gs.eff_condia;
                        switch (eff_c)
                        {
                            case "优":
                                replaceDic.Add("#tra1#", gs.ra_desa);
                                replaceDic.Add("#thw1#", gs.highway_desa);
                                replaceDic.Add("#tfs1#", gs.fs_desa);
                                replaceDic.Add("#tpt1#", gs.highway_desa);
                                replaceDic.Add("#tbz1#", "——");

                                replaceDic.Add("#ttra1#", Math.Round(gs.ra_ratea * 100.0 ,2 ).ToString("F2"));
                                replaceDic.Add("#tthw1#", Math.Round(gs.highway_ratea * 100.0,2).ToString("F2"));
                                replaceDic.Add("#ttfs1#", Math.Round(gs.fs_ratea * 100.0,2).ToString("F2"));
                                replaceDic.Add("#ttgk1#", Math.Round(gs.port_ratea * 100.0,2).ToString("F2"));
                                replaceDic.Add("#ttjc1#", Math.Round(gs.infra_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttzr1#", Math.Round(gs.nature_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttjj1#", Math.Round(gs.icd_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttdl1#", Math.Round(gs.rr_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttgh1#", Math.Round(gs.icd_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttbz1#%", "——");
                                replaceDic.Add("#ttdl1#", Math.Round(gs.rl_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttlj1#", Math.Round(gs.sr_typea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttlt1#", Math.Round(gs.sr_condia * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttxz1#", Math.Round(gs.land_shapea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttmj1#", Math.Round(gs.land_areaa * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttzy1#", Math.Round(gs.al_typea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttds1#", Math.Round(gs.terrain_condia * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttgx1#", Math.Round(gs.plan_limita * 100.0, 2).ToString("F2"));
                                break;
                            case "较优":
                                replaceDic.Add("#tra2#", gs.ra_desa);
                                replaceDic.Add("#thw2#", gs.highway_desa);
                                replaceDic.Add("#tfs2#", gs.fs_desa);
                                replaceDic.Add("#tpt2#", gs.highway_desa);
                                replaceDic.Add("#tbz2#", "——");

                                replaceDic.Add("#ttra2#", Math.Round(gs.ra_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#tthw2#", Math.Round(gs.highway_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttfs2#", Math.Round(gs.fs_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttgk2#", Math.Round(gs.port_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttjc2#", Math.Round(gs.infra_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttzr2#", Math.Round(gs.nature_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttjj2#", Math.Round(gs.icd_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttdl2#", Math.Round(gs.rr_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttgh2#", Math.Round(gs.icd_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttbz2#%", "——");
                                replaceDic.Add("#ttdl2#", Math.Round(gs.rl_ratea * 100.0 ,2).ToString("F2"));
                                replaceDic.Add("#ttlj2#", Math.Round(gs.sr_typea * 100.0,2).ToString("F2"));
                                replaceDic.Add("#ttlt2#", Math.Round(gs.sr_condia * 100.0,2).ToString("F2"));
                                replaceDic.Add("#ttxz2#", Math.Round(gs.land_shapea * 100.0 ,2 ).ToString("F2"));
                                replaceDic.Add("#ttmj2#", Math.Round(gs.land_areaa * 100.0,2).ToString("F2"));
                                replaceDic.Add("#ttzy2#", Math.Round(gs.al_typea * 100.0,2).ToString("F2"));
                                replaceDic.Add("#ttds2#", Math.Round(gs.terrain_condia * 100.0,2).ToString("F2"));
                                replaceDic.Add("#ttgx2#", Math.Round(gs.plan_limita * 100.0,2).ToString("F2"));
                                break;
                            case "一般":
                                replaceDic.Add("#tra3#", gs.ra_desa);
                                replaceDic.Add("#thw3#", gs.highway_desa);
                                replaceDic.Add("#tfs3#", gs.fs_desa);
                                replaceDic.Add("#tpt3#", gs.highway_desa);
                                replaceDic.Add("#tbz3#", "——");
                                replaceDic.Add("#ttbz5#%", "——");
                                replaceDic.Add("#ttgk5#%", "0.00%");
                                break;
                            case "较劣":
                                replaceDic.Add("#tra4#", gs.ra_desa);
                                replaceDic.Add("#thw4#", gs.highway_desa);
                                replaceDic.Add("#tfs4#", gs.fs_desa);
                                replaceDic.Add("#tpt4#", gs.highway_desa);
                                replaceDic.Add("#tbz4#", "——");

                                replaceDic.Add("#ttra3#", Math.Round(gs.ra_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#tthw3#", Math.Round(gs.highway_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttfs3#", Math.Round(gs.fs_ratea * 100.0,2).ToString("F2"));
                                replaceDic.Add("#ttgk3#", Math.Round(gs.port_ratea * 100.0,2).ToString("F2"));
                                replaceDic.Add("#ttjc3#", Math.Round(gs.infra_ratea * 100.0,2).ToString("F2"));
                                replaceDic.Add("#ttzr3#", Math.Round(gs.nature_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttjj3#", Math.Round(gs.icd_ratea * 100.0,2).ToString("F2"));
                                replaceDic.Add("#ttdl3#", Math.Round(gs.rr_ratea * 100.0,2).ToString("F2"));
                                replaceDic.Add("#ttgh3#", Math.Round(gs.icd_ratea * 100.0, 2).ToString("F2")) ;
                                replaceDic.Add("#ttbz3#%", "——");
                                replaceDic.Add("#ttdl3#", (gs.rl_ratea * 100.0).ToString("F2"));
                                replaceDic.Add("#ttlj3#", (gs.sr_typea * 100.0).ToString("F2"));
                                replaceDic.Add("#ttlt3#", (gs.sr_condia * 100.0).ToString("F2"));
                                replaceDic.Add("#ttxz3#", (gs.land_shapea * 100.0).ToString("F2"));
                                replaceDic.Add("#ttmj3#", (gs.land_areaa * 100.0).ToString("F2"));
                                replaceDic.Add("#ttzy3#", (gs.al_typea * 100.0).ToString("F2"));
                                replaceDic.Add("#ttds3#", (gs.terrain_condia * 100.0).ToString("F2"));
                                replaceDic.Add("#ttgx3#", (gs.plan_limita * 100.0).ToString("F2"));
                                break;
                            case "劣":
                                replaceDic.Add("#tra5#", gs.ra_desa);
                                replaceDic.Add("#thw5#", gs.highway_desa);
                                replaceDic.Add("#tfs5#", gs.fs_desa);
                                replaceDic.Add("#tpt5#", gs.highway_desa);
                                replaceDic.Add("#tbz5#", "——");

                                replaceDic.Add("#ttra4#", Math.Round(gs.ra_ratea * 100.0,2).ToString("F2"));
                                replaceDic.Add("#tthw4#", Math.Round(gs.highway_ratea * 100.0,2).ToString("F2"));
                                replaceDic.Add("#ttfs4#", Math.Round(gs.fs_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttgk4#", Math.Round(gs.port_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttjc4#", Math.Round(gs.infra_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttzr4#", Math.Round(gs.nature_ratea * 100.0,2).ToString("F2"));
                                replaceDic.Add("#ttjj4#", Math.Round(gs.icd_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttdl4#", Math.Round(gs.rr_ratea * 100.0,2).ToString("F2"));
                                replaceDic.Add("#ttgh4#", Math.Round(gs.icd_ratea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttbz4#%", "——");
                                replaceDic.Add("#ttdl4#", Math.Round(gs.rl_ratea * 100.0,2).ToString("F2"));
                                replaceDic.Add("#ttlj4#", Math.Round(gs.sr_typea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttlt4#", Math.Round(gs.sr_condia * 100.0,2).ToString("F2"));
                                replaceDic.Add("#ttxz4#", Math.Round(gs.land_shapea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttmj4#", Math.Round(gs.land_areaa * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttzy4#", Math.Round(gs.al_typea * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttds4#", Math.Round(gs.terrain_condia * 100.0, 2).ToString("F2"));
                                replaceDic.Add("#ttgx4#", Math.Round(gs.plan_limita * 100.0, 2).ToString("F2"));
                                break;
                            default:
                                break;
                        }
                    }
                    var cclopaa = coblps.Where(t => t.region_name == "市区" && t.usetype == "商服").OrderBy(t => t.level).ToList();
                    replaceDic.Add("#SF_D#", cclopaa[0].price_define);
                    replaceDic.Add("#KFCDS#", cclopaa[0].ld_rate);
                    int cout = 1;
                    for(int i = 0; i < cclopaa.Count; i++)
                    {
                        replaceDic.Add(string.Format("#SP{0}#", cout), cclopaa[i].plot_ratio.ToString());
                        cout += 1;
                    }
                    if(cout < 7)
                    {
                        for(int i = cout; cout < 7; cout ++ )
                         replaceDic.Add(string.Format("#SP{0}#", cout), "");
                    }


                    cout = 1;
                    cclopaa = coblps.Where(t => t.region_name == "市区" && t.usetype == "住宅").OrderBy(t => t.level).ToList();
                    replaceDic.Add("#住宅R#", "住宅");
                    replaceDic.Add("#ZZ_D#", cclopaa[0].price_define);
                    replaceDic.Add("#KFCDZ#", cclopaa[0].ld_rate);
                    for (int i = 0; i < cclopaa.Count; i++)
                    {
                        replaceDic.Add(string.Format("#ZP{0}#", cout), cclopaa[i].plot_ratio.ToString());
                        cout += 1;
                    }
                    if (cout < 7)
                    {
                        for (int i = cout; cout < 7; cout++)
                            replaceDic.Add(string.Format("#ZP{0}#", cout), "");
                    }

                    cout = 1;
                    cclopaa = coblps.Where(t => t.region_name == "市区" && t.usetype == "工业").OrderBy(t => t.level).ToList();
                    //replaceDic.Add("#住宅R#", "住宅");
                    replaceDic.Add("#GY_D#", cclopaa[0].price_define);
                    replaceDic.Add("#KFCDG#", cclopaa[0].ld_rate);
                    for (int i = 0; i < cclopaa.Count; i++)
                    {
                        replaceDic.Add(string.Format("#GP{0}#", cout), cclopaa[i].plot_ratio.ToString());
                        cout += 1;
                    }
                    if (cout < 7)
                    {
                        for (int i = cout; cout < 7; cout++)
                            replaceDic.Add(string.Format("#GP{0}#", cout), "");
                    }

                    cout = 1;
                    cclopaa = coblps.Where(t => t.region_name == "市区" && t.usetype == "公服").OrderBy(t => t.level).ToList();
                    replaceDic.Add("#公服R#", "公服");
                    replaceDic.Add("#GF_D#", cclopaa[0].price_define);
                    replaceDic.Add("#KFCDGF#", cclopaa[0].ld_rate);
                    for (int i = 0; i < cclopaa.Count; i++)
                    {
                        replaceDic.Add(string.Format("#GF{0}#", cout), cclopaa[i].plot_ratio.ToString());
                        cout += 1;
                    }
                    if (cout < 7)
                    {
                        for (int i = cout; cout < 7; cout++)
                            replaceDic.Add(string.Format("#GF{0}#", cout), "");
                    }

                    var selItemXc = gs_Ccoblps.Where(t => t.ra_ratea == details.zsra_regex).First().ra_desa;
                    replaceDic.Add("#ra_desa#", selItemXc);
                    replaceDic.Add("#ra_ratea#", Math.Round(details.zsra_regex * 100.0, 2).ToString());

                    selItemXc = gs_Ccoblps.Where(t => t.highway_ratea == details.zshighway_regex).First().highway_desa;
                    replaceDic.Add("#highway_desa#", selItemXc);
                    replaceDic.Add("#highway_ratea#", Math.Round(details.zshighway_regex * 100.0, 2).ToString());

                    selItemXc = gs_Ccoblps.Where(t => t.fs_ratea == details.zsfs_regex).First().fs_desa;
                    replaceDic.Add("#fs_desa#", selItemXc);
                    replaceDic.Add("#fs_ratea#", Math.Round(details.zsfs_regex * 100.0, 2).ToString());

                    double gkmt = details.zsgkmt_regex ?? 0.0;
                    selItemXc = gs_Ccoblps.Where(t => t.port_ratea == gkmt).First().fs_desa;
                    replaceDic.Add("#port_desa#", selItemXc);
                    replaceDic.Add("#port_ratea#", Math.Round(gkmt * 100.0, 2).ToString());

                    selItemXc = gs_Ccoblps.Where(t => t.infra_ratea == details.zsinfra_regex).First().infra_desa;
                    replaceDic.Add("#infra_desa#", selItemXc);
                    replaceDic.Add("#infra_ratea#", Math.Round(details.zsinfra_regex * 100.0, 2).ToString());

                    selItemXc = gs_Ccoblps.Where(t => t.nature_ratea == details.zsnature_regex).First().nature_desa;
                    replaceDic.Add("#nature_desa#", selItemXc);
                    replaceDic.Add("#nature_ratea#", Math.Round(details.zsnature_regex * 100.0, 2).ToString());

                    selItemXc = gs_Ccoblps.Where(t => t.icd_ratea == details.zsicd_regex).First().icd_desa;
                    replaceDic.Add("#icd_desa#", selItemXc);
                    replaceDic.Add("#icd_ratea#", Math.Round(details.zsicd_regex * 100.0, 2).ToString());

                    selItemXc = gs_Ccoblps.Where(t => t.rr_ratea == details.zsrr_regex).First().rr_desa;
                    replaceDic.Add("#rr_desa#", selItemXc);
                    replaceDic.Add("#rr_ratea#", Math.Round(details.zsrr_regex * 100.0, 2).ToString());

                    double qyyd = details.zsqyyd_regex ?? 0.0;
                    selItemXc = gs_Ccoblps.Where(t => t.rl_ratea == qyyd).First().rl_desa;
                    replaceDic.Add("#rl_desa#", selItemXc);
                    replaceDic.Add("#rl_ratea#", Math.Round(qyyd * 100.0, 2).ToString());

                    replaceDic.Add("#rg_desa#", "——");
                    replaceDic.Add("#rg_ratea#%", "——");

                    selItemXc = gs_Ccoblps.Where(t => t.sr_typea == details.zssr_regex).First().sr_desa;
                    replaceDic.Add("#sr_desa#", selItemXc);
                    replaceDic.Add("#sr_ratea#", Math.Round(details.zssr_regex * 100.0, 2).ToString());

                    selItemXc = gs_Ccoblps.Where(t => t.sr_condia == details.zssrc_regex).First().src_desa;
                    replaceDic.Add("#src_desa#", selItemXc);
                    replaceDic.Add("#src_ratea#", Math.Round(details.zssrc_regex * 100.0, 2).ToString());

                    selItemXc = gs_Ccoblps.Where(t => t.land_shapea == details.zsshape_regex).First().shape_desa;
                    replaceDic.Add("#shape_desa#", selItemXc);
                    replaceDic.Add("#shape_ratea#", Math.Round(details.zsshape_regex * 100.0, 2).ToString());

                    selItemXc = gs_Ccoblps.Where(t => t.land_areaa == details.zsmj_regex).First().area_desa;
                    replaceDic.Add("#area_desa#", selItemXc);
                    replaceDic.Add("#area_ratea#", Math.Round(details.zsmj_regex * 100.0, 2).ToString());

                    selItemXc = gs_Ccoblps.Where(t => t.al_typea == details.zsal_regex).First().al_desa;
                    replaceDic.Add("#al_desa#", selItemXc);
                    replaceDic.Add("#al_ratea#", Math.Round(details.zsal_regex * 100.0, 2).ToString());

                    selItemXc = gs_Ccoblps.Where(t => t.terrain_condia == details.zsterrain_regex).First().terrain_desa;
                    replaceDic.Add("#errain_desa#", selItemXc);
                    replaceDic.Add("#errain_ratea#", Math.Round(details.zsal_regex * 100.0, 2).ToString());

                    selItemXc = gs_Ccoblps.Where(t => t.plan_limita == details.zsplan_regex).First().plan_desa;
                    replaceDic.Add("#plan_desa#", selItemXc);
                    replaceDic.Add("#plan_ratea#", Math.Round(details.zsplan_regex * 100.0, 2).ToString());
                }
            }
            else
            {
                var wzCCCs = wz_Ccoblps.Where(t => t.use_levela == material.use_level).ToList();
                foreach (var wz in wzCCCs)
                {
                    string eff_c = wz.eff_condia;
                    switch (eff_c)
                    {
                        case "优":
                            replaceDic.Add("#tra1#", wz.ra_desa);
                            replaceDic.Add("#thw1#", wz.highway_desa);
                            replaceDic.Add("#tfs1#", wz.fs_desa);
                            replaceDic.Add("#tbz1#", wz.rg_desa);
                            replaceDic.Add("#tpt1#", "——");

                            replaceDic.Add("#ttra1#", Math.Round(wz.ra_ratea * 100.0,2).ToString());
                            replaceDic.Add("#tthw1#", Math.Round(wz.highway_ratea * 100.0,2).ToString());
                            replaceDic.Add("#ttfs1#", Math.Round(wz.fs_ratea * 100.0, 2).ToString());//#ttgk1#%
                            replaceDic.Add("#ttgk1#%", "——");
                            replaceDic.Add("#ttbz1#", Math.Round(wz.rg_ratea * 100.0,2).ToString());
                            replaceDic.Add("#ttjc1#", Math.Round(wz.infra_ratea * 100.0,2).ToString());
                            replaceDic.Add("#ttzr1#", Math.Round(wz.nature_ratea * 100.0,2).ToString());
                            replaceDic.Add("#ttjj1#", Math.Round(wz.icd_ratea * 100.0, 2).ToString());
                            replaceDic.Add("#ttdl1#", Math.Round(wz.rr_ratea * 100.0,2).ToString());
                            replaceDic.Add("#ttgh1#", (wz.icd_ratea * 100.0).ToString());
                            //replaceDic.Add("#ttdl1#", (wz.rr_ratea * 100.0).ToString());
                            replaceDic.Add("#ttlj1#", Math.Round(wz.sr_typea * 100.0, 2).ToString());
                            replaceDic.Add("#ttlt1#", Math.Round(wz.sr_condia * 100.0,2).ToString());
                            replaceDic.Add("#ttxz1#", Math.Round(wz.land_shapea * 100.0, 2).ToString());
                            replaceDic.Add("#ttmj1#", Math.Round(wz.land_areaa * 100.0, 2).ToString());
                            replaceDic.Add("#ttzy1#", Math.Round(wz.al_typea * 100.0, 2).ToString());
                            replaceDic.Add("#ttds1#", Math.Round(wz.terrain_condia * 100.0, 2).ToString());
                            replaceDic.Add("#ttgx1#", Math.Round(wz.plan_limita * 100.0, 2 ).ToString());
                            break;
                        case "较优":
                            replaceDic.Add("#tra2#", wz.ra_desa);
                            replaceDic.Add("#thw2#", wz.highway_desa);
                            replaceDic.Add("#tfs2#", wz.fs_desa);
                            replaceDic.Add("#tbz2#", wz.rg_desa);
                            replaceDic.Add("#tpt2#", "——");

                            replaceDic.Add("#ttra2#", Math.Round(wz.ra_ratea * 100.0,2).ToString());
                            replaceDic.Add("#tthw2#", Math.Round(wz.highway_ratea * 100.0,2).ToString());
                            replaceDic.Add("#ttfs2#", Math.Round(wz.fs_ratea * 100.0, 2).ToString());
                            replaceDic.Add("#ttgk2#%", "——");
                            replaceDic.Add("#ttbz2#", Math.Round(wz.rg_ratea * 100.0, 2).ToString());
                            replaceDic.Add("#ttjc2#", Math.Round(wz.infra_ratea * 100.0, 2).ToString());
                            replaceDic.Add("#ttzr2#", Math.Round(wz.nature_ratea * 100.0, 2).ToString());
                            replaceDic.Add("#ttjj2#", Math.Round(wz.icd_ratea * 100.0, 2).ToString());
                            replaceDic.Add("#ttdl2#", Math.Round(wz.rr_ratea * 100.0, 2).ToString());
                            replaceDic.Add("#ttgh2#", Math.Round(wz.icd_ratea * 100.0, 2).ToString());
                            //replaceDic.Add("#ttdl2#", (wz.rr_ratea * 100.0).ToString());
                            replaceDic.Add("#ttlj2#", Math.Round(wz.sr_typea * 100.0, 2).ToString());
                            replaceDic.Add("#ttlt2#", Math.Round(wz.sr_condia * 100.0, 2).ToString());
                            replaceDic.Add("#ttxz2#", Math.Round(wz.land_shapea * 100.0, 2).ToString());
                            replaceDic.Add("#ttmj2#", Math.Round(wz.land_areaa * 100.0, 2).ToString());
                            replaceDic.Add("#ttzy2#", Math.Round(wz.al_typea * 100.0, 2).ToString());
                            replaceDic.Add("#ttds2#", Math.Round(wz.terrain_condia * 100.0, 2).ToString());
                            replaceDic.Add("#ttgx2#", Math.Round(wz.plan_limita * 100.0, 2 ).ToString());
                            break;
                        case "一般":
                            replaceDic.Add("#tra3#", wz.ra_desa);
                            replaceDic.Add("#thw3#", wz.highway_desa);
                            replaceDic.Add("#tfs3#", wz.fs_desa);
                            replaceDic.Add("#tbz3#", wz.rg_desa);
                            replaceDic.Add("#tpt3#", "——");
                            replaceDic.Add("#ttgk5#%", "——");//
                            replaceDic.Add("#ttbz5#%", "0.00%");
                            break;
                        case "较劣":
                            replaceDic.Add("#tra4#", wz.ra_desa);
                            replaceDic.Add("#thw4#", wz.highway_desa);
                            replaceDic.Add("#tfs4#", wz.fs_desa);
                           // replaceDic.Add("#tpt4#", wz.highway_desa);
                            replaceDic.Add("#tbz4#", wz.rg_desa);
                            replaceDic.Add("#tpt4#", "——");

                            replaceDic.Add("#ttra3#", Math.Round(wz.ra_ratea * 100.0,2).ToString("F2"));
                            replaceDic.Add("#tthw3#", Math.Round(wz.highway_ratea * 100.0,2).ToString("F2"));
                            replaceDic.Add("#ttfs3#", Math.Round(wz.fs_ratea * 100.0,2).ToString("F2"));
                            replaceDic.Add("#ttgk3#%", "——");
                            replaceDic.Add("#ttbz3#", Math.Round(wz.rg_ratea * 100.0, 2).ToString("F2"));
                            replaceDic.Add("#ttjc3#", Math.Round(wz.infra_ratea * 100.0, 2).ToString("F2"));
                            replaceDic.Add("#ttzr3#", Math.Round(wz.nature_ratea * 100.0, 2).ToString("F2"));
                            replaceDic.Add("#ttjj3#", Math.Round(wz.icd_ratea * 100.0, 2).ToString("F2"));
                            replaceDic.Add("#ttdl3#", Math.Round(wz.rr_ratea * 100.0, 2).ToString("F2"));
                            replaceDic.Add("#ttgh3#", Math.Round(wz.icd_ratea * 100.0, 2).ToString("F2"));
                            //replaceDic.Add("#ttdl3#", (wz.rr_ratea * 100.0).ToString());
                            replaceDic.Add("#ttlj3#", Math.Round(wz.sr_typea * 100.0, 2).ToString("F2"));
                            replaceDic.Add("#ttlt3#", Math.Round(wz.sr_condia * 100.0, 2).ToString("F2"));
                            replaceDic.Add("#ttxz3#", Math.Round(wz.land_shapea * 100.0, 2).ToString("F2"));
                            replaceDic.Add("#ttmj3#", Math.Round(wz.land_areaa * 100.0, 2).ToString("F2"));
                            replaceDic.Add("#ttzy3#", Math.Round(wz.al_typea * 100.0, 2).ToString("F2"));
                            replaceDic.Add("#ttds3#", Math.Round(wz.terrain_condia * 100.0, 2).ToString("F2"));
                            replaceDic.Add("#ttgx3#", Math.Round(wz.plan_limita * 100.0, 2).ToString("F2"));
                            break;
                        case "劣":
                            replaceDic.Add("#tra5#", wz.ra_desa);
                            replaceDic.Add("#thw5#", wz.highway_desa);
                            replaceDic.Add("#tfs5#", wz.fs_desa);
                            replaceDic.Add("#tbz5#", wz.rg_desa);
                            replaceDic.Add("#tpt5#", "——");

                            replaceDic.Add("#ttra4#", Math.Round(wz.ra_ratea * 100.0, 2).ToString());
                            replaceDic.Add("#tthw4#", Math.Round(wz.highway_ratea * 100.0, 2).ToString());
                            replaceDic.Add("#ttfs4#", Math.Round(wz.fs_ratea * 100.0, 2).ToString());
                            replaceDic.Add("#ttgk4#%", "——");
                            replaceDic.Add("#ttbz4#", Math.Round(wz.rg_ratea * 100.0, 2).ToString());
                            replaceDic.Add("#ttjc4#", Math.Round(wz.infra_ratea * 100.0, 2).ToString());
                            replaceDic.Add("#ttzr4#", Math.Round(wz.nature_ratea * 100.0, 2).ToString());
                            replaceDic.Add("#ttjj4#", Math.Round(wz.icd_ratea * 100.0, 2).ToString());
                            replaceDic.Add("#ttdl4#", Math.Round(wz.rr_ratea * 100.0, 2).ToString());
                            replaceDic.Add("#ttgh4#", Math.Round(wz.icd_ratea * 100.0, 2).ToString());
                            //replaceDic.Add("#ttdl4#", (wz.rr_ratea * 100.0).ToString());
                            replaceDic.Add("#ttlj4#", Math.Round(wz.sr_typea * 100.0, 2).ToString());
                            replaceDic.Add("#ttlt4#", Math.Round(wz.sr_condia * 100.0, 2).ToString());
                            replaceDic.Add("#ttxz4#", Math.Round(wz.land_shapea * 100.0, 2).ToString());
                            replaceDic.Add("#ttmj4#", Math.Round(wz.land_areaa * 100.0, 2).ToString());
                            replaceDic.Add("#ttzy4#", Math.Round(wz.al_typea * 100.0, 2).ToString());
                            replaceDic.Add("#ttds4#", Math.Round(wz.terrain_condia * 100.0, 2).ToString());
                            replaceDic.Add("#ttgx4#", Math.Round(wz.plan_limita * 100.0, 2).ToString());
                            break;
                        default:
                            break;
                    }
                }
                var cclopaa = coblps.Where(t => t.region_name == "吴中区" && t.usetype == "商服").OrderBy(t => t.level).ToList();
                replaceDic.Add("#SF_D#", cclopaa[0].price_define);
                replaceDic.Add("#KFCDS#", cclopaa[0].ld_rate);
                int cout = 1;
                for (int i = 0; i < cclopaa.Count; i++)
                {
                    replaceDic.Add(string.Format("#SP{0}#", cout), cclopaa[i].plot_ratio.ToString());
                    cout += 1;
                }
                if (cout < 7)
                {
                    for (int i = cout; cout < 7; cout++)
                        replaceDic.Add(string.Format("#SP{0}#", cout), "");
                }


                cout = 1;
                cclopaa = coblps.Where(t => t.region_name == "吴中区" && t.usetype == "宅基地").OrderBy(t => t.level).ToList();
                replaceDic.Add("#住宅R#", "宅基地");
                replaceDic.Add("#ZZ_D#", cclopaa[0].price_define);
                replaceDic.Add("#KFCDZ#", cclopaa[0].ld_rate);
                for (int i = 0; i < cclopaa.Count; i++)
                {
                    replaceDic.Add(string.Format("#ZP{0}#", cout), cclopaa[i].plot_ratio.ToString());
                    cout += 1;
                }
                if (cout < 7)
                {
                    for (int i = cout; cout < 7; cout++)
                        replaceDic.Add(string.Format("#ZP{0}#", cout), "");
                }

                cout = 1;
                cclopaa = coblps.Where(t => t.region_name == "吴中区" && t.usetype == "工业").OrderBy(t => t.level).ToList();
                //replaceDic.Add("#住宅R#", "住宅");
                replaceDic.Add("#GY_D#", cclopaa[0].price_define);
                replaceDic.Add("#KFCDG#", cclopaa[0].ld_rate);
                for (int i = 0; i < cclopaa.Count; i++)
                {
                    replaceDic.Add(string.Format("#GP{0}#", cout), cclopaa[i].plot_ratio.ToString());
                    cout += 1;
                }
                if (cout < 7)
                {
                    for (int i = cout; cout < 7; cout++)
                        replaceDic.Add(string.Format("#GP{0}#", cout), "");
                }
                replaceDic.Add("#公服R#", "公服");
                replaceDic.Add("#GF_D#","——");
                replaceDic.Add("#GF1#", "——");
                replaceDic.Add("#GF2#", "——");
                replaceDic.Add("#GF3#", "——");
                replaceDic.Add("#GF4#", "——");
                replaceDic.Add("#GF5#", "——");
                replaceDic.Add("#GF6#", "——");
                replaceDic.Add("#KFCDGF#", "——");//
                replaceDic.Add("#port_des#", "——");
                replaceDic.Add("#port_desa#", "——");
                replaceDic.Add("#port_ratea#%", "——");

                var selItemXc = wz_Ccoblps.Where(t => t.ra_ratea == details.zsra_regex).First().ra_desa;
                replaceDic.Add("#ra_desa#", selItemXc);
                replaceDic.Add("#ra_ratea#", Math.Round(details.zsra_regex * 100.0, 2).ToString());

                selItemXc = wz_Ccoblps.Where(t => t.highway_ratea == details.zshighway_regex).First().highway_desa;
                replaceDic.Add("#highway_desa#", selItemXc);
                replaceDic.Add("#highway_ratea#", Math.Round(details.zshighway_regex * 100.0, 2).ToString());

                selItemXc = wz_Ccoblps.Where(t => t.fs_ratea == details.zsfs_regex).First().fs_desa;
                replaceDic.Add("#fs_desa#", selItemXc);
                replaceDic.Add("#fs_ratea#", Math.Round(details.zsfs_regex * 100.0, 2).ToString());

                
                //replaceDic.Add("#port_desa#", "——");
                //replaceDic.Add("#port_ratea#", "——");

                selItemXc = wz_Ccoblps.Where(t => t.infra_ratea == details.zsinfra_regex).First().infra_desa;
                replaceDic.Add("#infra_desa#", selItemXc);
                replaceDic.Add("#infra_ratea#", Math.Round(details.zsinfra_regex * 100.0, 2).ToString());

                selItemXc = wz_Ccoblps.Where(t => t.nature_ratea == details.zsnature_regex).First().nature_desa;
                replaceDic.Add("#nature_desa#", selItemXc);
                replaceDic.Add("#nature_ratea#", Math.Round(details.zsnature_regex * 100.0, 2).ToString());

                selItemXc = wz_Ccoblps.Where(t => t.icd_ratea == details.zsicd_regex).First().icd_desa;
                replaceDic.Add("#icd_desa#", selItemXc);
                replaceDic.Add("#icd_ratea#", Math.Round(details.zsicd_regex * 100.0, 2).ToString());

                selItemXc = wz_Ccoblps.Where(t => t.rr_ratea == details.zsrr_regex).First().rr_desa;
                replaceDic.Add("#rr_desa#", selItemXc);
                replaceDic.Add("#rr_ratea#", Math.Round(details.zsrr_regex * 100.0, 2).ToString());

//                 double qyyd = details.zsqyyd_regex ?? 0.0;
//                 selItemXc = wz_Ccoblps.Where(t => t.rl == qyyd).First().rl_desa;
                replaceDic.Add("#rl_desa#", "——");
                replaceDic.Add("#rl_ratea#", "——");

                double qyyd = details.zsrg_regex ?? 0.0;
                selItemXc = wz_Ccoblps.Where(t => t.rg_ratea == qyyd).First().rg_desa;
                replaceDic.Add("#rg_desa#", selItemXc);
                replaceDic.Add("#rg_ratea#%", Math.Round(qyyd * 100.0, 2).ToString());

                selItemXc = wz_Ccoblps.Where(t => t.sr_typea == details.zssr_regex).First().sr_desa;
                replaceDic.Add("#sr_desa#", selItemXc);
                replaceDic.Add("#sr_ratea#", Math.Round(details.zssr_regex * 100.0, 2).ToString());

                selItemXc = wz_Ccoblps.Where(t => t.sr_condia == details.zssrc_regex).First().src_desa;
                replaceDic.Add("#src_desa#", selItemXc);
                replaceDic.Add("#src_ratea#", Math.Round(details.zssrc_regex * 100.0, 2).ToString());

                selItemXc = wz_Ccoblps.Where(t => t.land_shapea == details.zsshape_regex).First().shape_desa;
                replaceDic.Add("#shape_desa#", selItemXc);
                replaceDic.Add("#shape_ratea#", Math.Round(details.zsshape_regex * 100.0, 2).ToString());

                selItemXc = wz_Ccoblps.Where(t => t.land_areaa == details.zsmj_regex).First().area_desa;
                replaceDic.Add("#area_desa#", selItemXc);
                replaceDic.Add("#area_ratea#", Math.Round(details.zsmj_regex * 100.0, 2).ToString());

                selItemXc = wz_Ccoblps.Where(t => t.al_typea == details.zsal_regex).First().al_desa;
                replaceDic.Add("#al_desa#", selItemXc);
                replaceDic.Add("#al_ratea#", Math.Round(details.zsal_regex * 100.0, 2).ToString());

                //selItemXc = wz_Ccoblps.Where(t => t.al_typea == details.zsal_regex).First().al_desa;
                //replaceDic.Add("#al_desa#", selItemXc);
                //replaceDic.Add("#al_ratea#", Math.Round(details.zsal_regex * 100.0, 2).ToString());

                selItemXc = wz_Ccoblps.Where(t => t.terrain_condia == details.zsterrain_regex).First().terrain_desa;
                replaceDic.Add("#terrain_desa#", selItemXc);
                replaceDic.Add("#terrain_ratea#", Math.Round(details.zsal_regex * 100.0, 2).ToString());

                selItemXc = wz_Ccoblps.Where(t => t.plan_limita == details.zsplan_regex).First().plan_desa;
                replaceDic.Add("#plan_desa#", selItemXc);
                replaceDic.Add("#plan_ratea#", Math.Round(details.zsplan_regex * 100.0, 2).ToString());
            }
            #endregion

            #region 替换字典添加参数
            replaceDic.Add("#delegate_name#", material.delegate_name);//委托方
            replaceDic.Add("#securities_address#", material.securities_address);//委托方地址
            replaceDic.Add("#ReportCode#", project.report_code);//报告编号
            replaceDic.Add("#ReportCodeTec#", project.tec_code);//报告技术编号
            DateTime dateOut = project.date_out;
            //CultureInfo ci = new CultureInfo("zh-CN");
            string chineseDateTime = ToChineseDateTime(dateOut);
            replaceDic.Add("#date_outCH#", chineseDateTime);//出具报告时间-中文
            replaceDic.Add("#value_date#", project.value_date.ToString("yyyy年M月d日"));//出具报告时间-中文
            replaceDic.Add("#businesslicense_type#", material.qllx ?? "");//权力类型
            //replaceDic.Add("#businesslicense_type#", material.businesslicense_type ?? "");//权力类型
            replaceDic.Add("#legal_person#", material.legal_person ?? "");//法人
            replaceDic.Add("#business_scope#", material.business_scope ?? "");//经营范围
            replaceDic.Add("#filename_ach#", guidanceDocument.filename_ach);//经营范围
            replaceDic.Add("#date_out#", project.date_out.ToString("yyyy年M月d日"));//出具报告时间
            replaceDic.Add("#land_outyear#", resultClass.mYearsCount.ToString());
            replaceDic.Add("#coblp_date#", coblp.date.ToString("yyyy年M月d日"));
            replaceDic.Add("#coblp_ratio#", coblp.plot_ratio.ToString());
            replaceDic.Add("#plot_ratio#", material.plot_ratio.ToString());
            replaceDic.Add("#sr_type#", material.sr_des);
            if (coblp.ld_rate.Contains("五通"))
            {
                replaceDic.Add("#tlms#", wtDes);
                replaceDic.Add("排污水状况: 排入市政污水管网；", "排污水状况:——");
                replaceDic.Add("排雨水状况: 排入市政污水管网；", "排雨水状况:——");
                replaceDic.Add("通燃气条件: 位于#region#电信局市话服务范围内；", "通燃气条件：——");
            }
            else if (coblp.ld_rate.Contains("六通"))
            {
                replaceDic.Add("#tlms#", ltDes);
                replaceDic.Add("排污水状况: 排入市政污水管网；", "排污水状况:——");
                replaceDic.Add("排雨水状况: 排入市政污水管网；", "排雨水状况:——");
            }    
            else
            {
                replaceDic.Add("#tlms#", qtDes);
            }

            replaceDic.Add("#estate#", material.estate ?? "");

            if(material.infra_des == "五通")
                replaceDic.Add("#Mtlms#", wtDes);
            else if (material.infra_des == "六通")
                replaceDic.Add("#Mtlms#", ltDes);
            else
                replaceDic.Add("#Mtlms#", qtDes);

            replaceDic.Add("#region#", material.regin ?? "");
            replaceDic.Add("#MtlmsSim#", material.infra_des ?? "");
            replaceDic.Add("#building_count#", material.building_count ?? "");
            double securities_areatotal = material.securities_areatotal ?? 0.0;
            if(securities_areatotal != 0.0)
                replaceDic.Add("#securities_areatotal#", securities_areatotal.ToString());
            else
                replaceDic.Add("#securities_areatotal#", "");

            replaceDic.Add("#gyqk#", material.gyqk ?? "");//bdcdyh
            replaceDic.Add("#bdcdyh#", material.bdcdyh ?? "");//securities_getdate
            string securities_getdate = string.Empty;
            if (material.securities_getdate is null)
                securities_getdate = "";
            else
            {
                DateTime dateTime = (DateTime)material.securities_getdate;
                securities_getdate = dateTime.ToString("yyyy年M月d日");
            }
            replaceDic.Add("#securities_getdate#", securities_getdate);
            replaceDic.Add("#building_status#", material.building_status ?? "");
            replaceDic.Add("#usages#", material.usages ?? "");

            double land_mj = material.land_mj ?? 0.0;
            if (securities_areatotal != 0.0)
                replaceDic.Add("#land_mj#", land_mj.ToString());
            else
                replaceDic.Add("#land_mj#", "");

            int ePrice = Convert.ToInt32((resultClass.zsPrice + resultClass.bjPrice) / 2);
            replaceDic.Add("#tddwjg#", ePrice.ToString());
            double totalPrice = Math.Round((ePrice * land_mj) / 10000.0, 2);
            replaceDic.Add("#tdzj#", totalPrice.ToString());
            double totalPriceA = totalPrice * 10000.0;
            NumConvertClass numConvertClass = new NumConvertClass();
            string chSum = numConvertClass.ConvertSum(totalPriceA.ToString());
            replaceDic.Add("#tdzjzj#", chSum);
            replaceDic.Add("#sr_des#", material.sr_des ?? "");
            replaceDic.Add("#src_des#", material.src_des ?? "");
            replaceDic.Add("#rea_des#", material.area_des ?? "");
            Appraiser gjs1 = appraiser.Where(t => t.id == project.gjs1).ToList()[0];
            Appraiser gjs2 = appraiser.Where(t => t.id == project.gjs2).ToList()[0];
            replaceDic.Add("#gjs1#", gjs1.name);
            replaceDic.Add("#appraiser_number1#", gjs1.number);
            replaceDic.Add("#gjs2#", gjs2.name);
            replaceDic.Add("#appraiser_number2#", gjs2.number);
            replaceDic.Add("#fourth_to#", material.fourth_to);

            string east_describe = material.east_describe ?? "";
            if(east_describe.Length == 0)
                replaceDic.Add("#east_describe#，",  "");
            else
                replaceDic.Add("#east_describe#", east_describe);

            string south_describe = material.south_describe ?? "";
            if(south_describe.Length == 0)
                replaceDic.Add("#south_describe#，", "");
            else
                replaceDic.Add("#south_describe#", south_describe);

            string west_describe = material.west_describe ?? "";
            if(west_describe.Length == 0)
                replaceDic.Add("#west_describe#，", "");
            else
                replaceDic.Add("#west_describe#", west_describe);

            string north_describe = material.north_describe ?? "";
            if(north_describe.Length == 0)
                replaceDic.Add("#north_describe#，",  "");
            else
                replaceDic.Add("#north_describe#", north_describe);

            replaceDic.Add("#street#", material.street ?? "");

            int land_money = material.land_money ?? 0;
            if(land_money != 0)
                replaceDic.Add("#landlevekBaseprice#", land_money.ToString());
            else
                replaceDic.Add("#landlevekBaseprice#", "");

            int land_level = material.use_level ?? 0;
            if(land_level != 0)
                replaceDic.Add("#landLevel#", land_level.ToString());
            else
                replaceDic.Add("#landLevel#", "");

            replaceDic.Add("#yynx#", (50.0 - resultClass.mYearsCount).ToString("F2"));

            if(material.plot_ratio > 0.8)
            {
                string aa = string.Format("容积率符合《工业项目建设用地控制指标》的要求。估价人员认为在现状用途和利用条件下，待估宗地达到最佳利用从而获得最大收益。");
                replaceDic.Add("#DES_ratio#", aa);
            }
            else
            {
                string aa = string.Format("根据苏州市人民政府《关于贯彻国务院深化改革严格土地管理的决定的实施意见》的规定，工业项目规划指标必须符合国土资源部颁发的《工业项目建设用地控制指标》标准，总体上建筑系数应大于0.5、容积率大于0.8。待估宗地目前建筑容积率为{0}，未达到该文件规定的下限，该宗地未达到最有效利用。",
                    material.plot_ratio);
                replaceDic.Add("#DES_ratio#", aa);
            }
            replaceDic.Add("#highway_des#", material.highway_des ?? "");
            replaceDic.Add("#fs_des#", material.fs_des ?? "");
            replaceDic.Add("#infra_des#", material.infra_des ?? "");
            replaceDic.Add("#terrain_des#", material.terrain_des ?? "");
            replaceDic.Add("#traffic_control#", material.traffic_control ?? "");
            replaceDic.Add("#area_des#", material.area_des ?? "");
            replaceDic.Add("#shape_des#", material.shape_des ?? "");
            replaceDic.Add("#securities_addressA#", caseA.securities_address);
            replaceDic.Add("#securities_addressB#", caseB.securities_address);
            replaceDic.Add("#securities_addressC#", caseC.securities_address);
            replaceDic.Add("#usagesA#", caseA.usages);
            replaceDic.Add("#usagesB#", caseB.usages);
            replaceDic.Add("#usagesC#", caseC.usages);
            replaceDic.Add("#land_mjA#", caseA.land_mj.ToString());
            replaceDic.Add("#land_mjB#", caseB.land_mj.ToString());
            replaceDic.Add("#land_mjC#", caseC.land_mj.ToString());
            replaceDic.Add("#ra_desA#", caseA.ra_des?? "");
            replaceDic.Add("#ra_desB#", caseB.ra_des?? "");
            replaceDic.Add("#ra_desC#", caseC.ra_des?? "");
            replaceDic.Add("#fs_desA#", caseA.fs_des?? "");
            replaceDic.Add("#fs_desB#", caseB.fs_des?? "");
            replaceDic.Add("#fs_desC#", caseC.fs_des?? "");
            replaceDic.Add("#highway_desA#", caseA.highway_des?? "");
            replaceDic.Add("#highway_desB#", caseB.highway_des?? "");
            replaceDic.Add("#highway_desC#", caseC.highway_des?? "");
            replaceDic.Add("#icd_des#", material.icd_des ?? "");
            replaceDic.Add("#icd_desA#", caseA.icd_des ?? "");
            replaceDic.Add("#icd_desB#", caseB.icd_des ?? "");
            replaceDic.Add("#icd_desC#", caseC.icd_des ?? "");
            replaceDic.Add("#area_desA#", caseA.area_des ?? "");
            replaceDic.Add("#area_desB#", caseB.area_des ?? "");
            replaceDic.Add("#area_desC#", caseC.area_des ?? "");
            replaceDic.Add("#shape_desA#", caseA.shape_des ?? "");
            replaceDic.Add("#shape_desB#", caseB.shape_des ?? "");
            replaceDic.Add("#shape_desC#", caseC.shape_des ?? "");
            replaceDic.Add("#sr_desA#", caseA.sr_des ?? "");
            replaceDic.Add("#sr_desB#", caseB.sr_des ?? "");
            replaceDic.Add("#sr_desC#", caseC.sr_des ?? "");
            replaceDic.Add("#src_desA#", caseA.src_des ?? "");
            replaceDic.Add("#src_desB#", caseB.src_des ?? "");
            replaceDic.Add("#src_desC#", caseC.src_des ?? "");
            replaceDic.Add("#filename_tec#", guidanceDocument.filename_tec ?? "");
            replaceDic.Add("#jy_date#", project.value_date.ToString("yyyy年M月d日")) ;
            DateTime jy_dateA = (DateTime)caseA.jy_date;
            replaceDic.Add("#jy_dateA#", jy_dateA.ToString("yyyy年M月d日"));
            DateTime jy_dateB = (DateTime)caseB.jy_date;
            replaceDic.Add("#jy_dateB#", jy_dateB.ToString("yyyy年M月d日"));
            DateTime jy_dateC = (DateTime)caseC.jy_date;
            replaceDic.Add("#jy_dateC#", jy_dateC.ToString("yyyy年M月d日"));

            replaceDic.Add("#land_moneyA#", caseA.land_money.ToString());
            replaceDic.Add("#land_moneyB#", caseB.land_money.ToString());
            replaceDic.Add("#land_moneyC#", caseC.land_money.ToString());

            replaceDic.Add("#plot_ratioA#", caseA.plot_ratio.ToString());
            replaceDic.Add("#plot_ratioB#", caseB.plot_ratio.ToString());
            replaceDic.Add("#plot_ratioC#", caseC.plot_ratio.ToString());

            if(caseA.infra_des.Contains("五通"))
                replaceDic.Add("#Atlms#", wtDes);
            else if (caseA.infra_des.Contains("六通"))
                replaceDic.Add("#Atlms#", ltDes);
            else
                replaceDic.Add("#Atlms#", qtDes);

            if (caseB.infra_des.Contains("五通"))
                replaceDic.Add("#Btlms#", wtDes);
            else if (caseB.infra_des.Contains("六通"))
                replaceDic.Add("#Btlms#", ltDes);
            else
                replaceDic.Add("#Btlms#", qtDes);

            if (caseC.infra_des.Contains("五通"))
                replaceDic.Add("#Ctlms#", wtDes);
            else if (caseC.infra_des.Contains("六通"))
                replaceDic.Add("#Ctlms#", ltDes);
            else
                replaceDic.Add("#Ctlms#", qtDes);

            replaceDic.Add("#land_outyearA#", "50");
            replaceDic.Add("#land_outyearB#", "50");
            replaceDic.Add("#land_outyearC#", "50");

            replaceDic.Add("#qlrA#", caseA.qlr);
            replaceDic.Add("#qlrB#", caseB.qlr);
            replaceDic.Add("#qlrC#", caseC.qlr);

            int mYear, mQuarter;
            DateTime mDate = project.value_date;
            mYear = mDate.Year;
            mQuarter = ((mDate.Month - 1) / 3) + 1;
            int refIndex = -1;
            var selItems = industryPriceindices.Where(t => t.year == mYear && t.quarter == mQuarter).ToList();
            replaceDic.Add("#jy_regex#", resultClass.mPriceIndex.ToString());
            replaceDic.Add("#jy_regexA#", resultClass.aPriceIndex.ToString());
            replaceDic.Add("#jy_regexB#", resultClass.bPriceIndex.ToString());
            replaceDic.Add("#jy_regexC#", resultClass.cPriceIndex.ToString());

            replaceDic.Add("#nq_regex#", resultClass.mLastYears.ToString());
            replaceDic.Add("#nq_regexA#", resultClass.aLastYears.ToString());
            replaceDic.Add("#nq_regexB#", resultClass.bLastYears.ToString());
            replaceDic.Add("#nq_regexC#", resultClass.cLastYears.ToString());
            replaceDic.Add("#ra_regex#", (details.ra_regex * 100.0).ToString());
            replaceDic.Add("#fs_regex#", (details.fs_regex * 100.0).ToString());
            replaceDic.Add("#highway_regex#", (details.highway_regex * 100.0).ToString());
            replaceDic.Add("#icd_regex#", (details.icd_regex * 100.0).ToString());
            replaceDic.Add("#mj_regex#", (details.mj_regex * 100.0).ToString());
            replaceDic.Add("#shape_regex#", (details.shape_regex * 100.0).ToString());
            replaceDic.Add("#sr_regex#", (details.sr_regex * 100.0).ToString());
            replaceDic.Add("#src_regex#", (details.src_regex * 100.0).ToString());

            replaceDic.Add("#raA#", resultClass.aRaRegex.ToString());
            replaceDic.Add("#raB#", resultClass.bRaRegex.ToString());
            replaceDic.Add("#raC#", resultClass.cRaRegex.ToString());

            replaceDic.Add("#fsA#", resultClass.aFsRegex.ToString());
            replaceDic.Add("#fsB#", resultClass.bFsRegex.ToString());
            replaceDic.Add("#fsC#", resultClass.cFsRegex.ToString());

            replaceDic.Add("#highwayA#", resultClass.aHighwayRegex.ToString());
            replaceDic.Add("#highwayB#", resultClass.bHighwayRegex.ToString());
            replaceDic.Add("#highwayC#", resultClass.cHighwayRegex.ToString());

            replaceDic.Add("#icdA#", resultClass.aIcdRegex.ToString());
            replaceDic.Add("#icdB#", resultClass.bIcdRegex.ToString());
            replaceDic.Add("#icdC#", resultClass.cIcdRegex.ToString());

            replaceDic.Add("#mjA#", resultClass.aMjRegex.ToString());
            replaceDic.Add("#mjB#", resultClass.bMjRegex.ToString());
            replaceDic.Add("#mjC#", resultClass.cMjRegex.ToString());

            replaceDic.Add("#shapeA#", resultClass.aShapeRegex.ToString());
            replaceDic.Add("#shapeB#", resultClass.bShapeRegex.ToString());
            replaceDic.Add("#shapeC#", resultClass.cShapeRegex.ToString());

            replaceDic.Add("#srA#", resultClass.aSrRegex.ToString());
            replaceDic.Add("#srB#", resultClass.bSrRegex.ToString());
            replaceDic.Add("#srC#", resultClass.cSrRegex.ToString());

            replaceDic.Add("#srcA#", resultClass.aSrcRegex.ToString());
            replaceDic.Add("#srcB#", resultClass.bSrcRegex.ToString());
            replaceDic.Add("#srcC#", resultClass.cSrcRegex.ToString());

            replaceDic.Add("#tRegexA#", resultClass.totalRegexA.ToString("F4"));
            replaceDic.Add("#tRegexB#", resultClass.totalRegexA.ToString("F4"));
            replaceDic.Add("#tRegexC#", resultClass.totalRegexA.ToString("F4"));

            double a = Math.Round((int)caseA.land_money * resultClass.totalRegexA, 2);
            replaceDic.Add("#jgA#", a.ToString());
            double b = Math.Round((int)caseB.land_money * resultClass.totalRegexB, 2);
            replaceDic.Add("#jgB#", b.ToString());
            double c = Math.Round((int)caseC.land_money * resultClass.totalRegexC, 2);
            replaceDic.Add("#jgC#", c.ToString());//#bjPrice2#
            replaceDic.Add("#bjPrice2#", Math.Round((a + b + c) / 3.0,2).ToString());
            replaceDic.Add("#bjPrice#", resultClass.bjPrice.ToString());
            replaceDic.Add("#announcement#", guidanceDocument.announcement);
            replaceDic.Add("#announcement_date#", guidanceDocument.announcement_date.ToString("yyyy年M月d日"));
            replaceDic.Add("#ZDplot_ratio#", coblp.plot_ratio.ToString());
            replaceDic.Add("#k2_regex#", resultClass.k2Regex.ToString("F4"));
            replaceDic.Add("#k3_regex#", resultClass.k3Regex.ToString("F4"));
            replaceDic.Add("#zsPrice#", resultClass.zsPrice.ToString());
            replaceDic.Add("#zsPrice2#", resultClass.zsPrice2.ToString());
            replaceDic.Add("#cclop_ldRate#", coblp.ld_rate);
            replaceDic.Add("#rp#", rr_item.r_price.ToString());
            replaceDic.Add("#ep#", rr_item.e_price.ToString());
            replaceDic.Add("#wp#", rr_item.w_price.ToString());
            replaceDic.Add("#cp#", rr_item.c_price.ToString());
            replaceDic.Add("#pp#", rr_item.l_price.ToString());
            replaceDic.Add("#tp#", rr_item.t_price.ToString());
            replaceDic.Add("#infra_regex#", resultClass.infraPrice.ToString());
            replaceDic.Add("#rr_des#", material.rr_des.ToString());
            replaceDic.Add("#nature_des#", material.nature_des.ToString());
            replaceDic.Add("#rl_des#", material.rl_des.ToString());
            replaceDic.Add("#rg_des#", material.rg_des.ToString());
            replaceDic.Add("#al_des#", material.al_des.ToString());
            replaceDic.Add("#plan_des#", material.plan_des.ToString());
            replaceDic.Add("#ki_regex#", resultClass.regesJZDXE);

            replaceDic.Add("#ra_des#", material.ra_des);//#bjPrice2#
                                                        //replaceDic.Add("#highway_des#", material.highway_des);
                                                        // replaceDic.Add("#fs_des#", material.fs_des);
            DateTime fbDate = guidanceDocument.announcement_date;

            int docYear = fbDate.Year;
            int docQuarter = ((fbDate.Month - 1) / 3) + 1;
            refIndex = -1;
            double fbPriceindex = FindPriceIndex(industryPriceindices, docYear, docQuarter, ref refIndex);
            replaceDic.Add("#announcement_regex#", fbPriceindex.ToString("F2"));


            //replaceDic.Add("#announcement_date#", guidanceDocument.announcement_date.ToString("yyyy年M月d日"));
            //replaceDic.Add("#ZDplot_ratio#", coblp.plot_ratio.ToString());
            //replaceDic.Add("#k2_regex#", resultClass.k2Regex.ToString());
            //replaceDic.Add("#k3_regex#", resultClass.k3Regex.ToString());
            //replaceDic.Add("#zsPrice#", resultClass.zsPrice.ToString());
            //replaceDic.Add("#zsPrice2#", resultClass.zsPrice2.ToString());
            //replaceDic.Add("#cclop_ldRate#", coblp.ld_rate);
            //replaceDic.Add("#rp#", rr_item.r_price.ToString());
            //replaceDic.Add("#ep#", rr_item.e_price.ToString());
            //replaceDic.Add("#wp#", rr_item.w_price.ToString());
            //replaceDic.Add("#cp#", rr_item.c_price.ToString());
            //replaceDic.Add("#pp#", rr_item.l_price.ToString());
            //replaceDic.Add("#tp#", rr_item.t_price.ToString());
            //replaceDic.Add("#infra_regex#", resultClass.infraPrice.ToString());
            if (rr_item.s_price == 0)
                replaceDic.Add("#sp#", "");
            else
                replaceDic.Add("#sp#", rr_item.s_price.ToString());
            if (rr_item.ss_price == 0)
                replaceDic.Add("#ssp#", "");
            else
                replaceDic.Add("#ssp#", rr_item.ss_price.ToString());
            if (rr_item.sr_price == 0)
                replaceDic.Add("#srp#", "");
            else
                replaceDic.Add("#srp#", rr_item.g_price.ToString());
            if (rr_item.g_price == 0)
                replaceDic.Add("#gp#", "");
            else
                replaceDic.Add("#gp#", rr_item.g_price.ToString());


            if (selItems.Count == 0)
            {
                int refIndexA = -1;
                FindPriceIndex(industryPriceindices,mYear, mQuarter,ref refIndex);
                string replaceString = string.Format("{0}年{1}季度地价指数未公布，考虑到工业用地地价平稳，近期无重大波动，因此，本次估价过程中{2}年{3}季度指数以日期上最接近的{4}年{5}季度的地价指数为准",
                    mYear,mQuarter,mYear,mQuarter, industryPriceindices[refIndex].year, industryPriceindices[refIndex].quarter);
                replaceDic.Add("#PriceIndexDescribe#", replaceString);
                int count = 12;
                for (int i = 0; i < 12; i++)
                {
                    DateTime prevQuarter = mDate.AddMonths(-3 * i);
                    string str = string.Format("{0}年第{1}季度", prevQuarter.Year, ((prevQuarter.Month - 1) / 3) + 1);
                    //string quarterString = prevQuarter.ToString("yyyy-Q") + "季度";
                    string rStringD = string.Format("#Date{0}#", count);
                    string rStringI = string.Format("#index{0}#", count);
                    replaceDic.Add(rStringD, str);

                    int iYears = prevQuarter.Year;
                    int iQuarter = ((prevQuarter.Month - 1) / 3) + 1;
                    var selItemsI = industryPriceindices.Where(t => t.year == iYears && t.quarter == iQuarter).ToList();
                    if(selItemsI.Count == 0)
                        replaceDic.Add(rStringI, "——");
                    else
                        replaceDic.Add(rStringI, selItemsI[0].price_index.ToString());
                    count -= 1;
                }
            }
            else
            {
                replaceDic.Add("#PriceIndexDescribe#。", "");
                int count = 12;
                for (int i = 0; i < 12; i++)
                {
                    DateTime prevQuarter = mDate.AddMonths(-3 * i);
                    string str = string.Format("{0}年第{1}季度", prevQuarter.Year, ((prevQuarter.Month - 1) / 3) + 1);
                    //string quarterString = mDate.ToString("yyyy-Q") + "季度";
                    string rStringD = string.Format("#Date{0}#", count);
                    string rStringI = string.Format("#Index{0}#", count);
                    replaceDic.Add(rStringD, str);

                    int iYears = prevQuarter.Year;
                    int iQuarter = ((mDate.Month - 1) / 3) + 1;
                    var selItemsI = industryPriceindices.Where(t => t.year == iYears && t.quarter == iQuarter).ToList();
                    replaceDic.Add(rStringI, selItemsI[0].price_index.ToString());
                    count -= 1;
                }
            }




            ImageDetails image = new ImageDetails();
            image.replaceWord = "#img1#";
#if DEBUG
            image.imagePath = @"D:\wallpaper\01.jpg";
#else
             image.imagePath = string.Format("{0}{1}/etc.png", picPathA, material.bdcdyh);  
#endif

            image.width = 312f;
            image.height = 209f;
            imageDetails.Add(image);

            ImageDetails image1 = new ImageDetails();
            image1.replaceWord = "#img2#";
#if DEBUG
            image1.imagePath = @"D:\wallpaper\02.jpg";
#else
            image1.imagePath = string.Format("{0}{1}/etc.png", picPathProj, project.projectid);
#endif
            image1.width = 312f;
            image1.height = 209f;
            imageDetails.Add(image1);
            #endregion
            ReplaceInWord rw = new ReplaceInWord(modulePath, replaceDic, imageDetails,material.bdcdyh ?? "",project);
            project.p_path = rw.filePath;
            _context.Entry(project).State = EntityState.Modified;
            await _context.SaveChangesAsync();
            mess = new JsonResult(new { Message = rw.filePath });
            return mess;
        }

        private bool Land_MaterialExists(int id)
        {
            return (_context.land_material?.Any(e => e.id == id)).GetValueOrDefault();
        }

        private double FindPriceIndex(List<Industry_Priceindex> priceIndexList,int targetYear,int targetQuarter,ref int refIndex)
        {
            Industry_Priceindex foundPriceIndex = priceIndexList
    .       FirstOrDefault(p => p.year == targetYear && p.quarter == targetQuarter);

            if (foundPriceIndex != null)
                return foundPriceIndex.price_index;
            else
            {
                // 按year排序，找到最接近目标年份的元素
                var sorted = priceIndexList.OrderByDescending(p => p.year).ThenByDescending(p => p.quarter).First();
                refIndex = priceIndexList.IndexOf(sorted);
                return sorted.price_index;
            }
        }

        private int FindIntervalIndex(List<DoubleInterval> intervals, double value)
        {
            for (int i = 0; i < intervals.Count; i++)
            {
                if (intervals[i].Contains(value))
                {
                    return i;
                }
            }

            return -1;
        }

        private string ToChineseDateTime(DateTime dateTime)
        {
            string[] yearNumbers = { "O", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
            string[] monthNumbers = { "", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二" };
            string[] dayNumbers = { "O", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十", "二十一", "二十二", "二十三", "二十四", "二十五", "二十六", "二十七", "二十八", "二十九", "三十", "三十一" };


            string year = "";
            string month = "";
            string day = "";

            // 转换年份
            string yearString = dateTime.Year.ToString();
            foreach (char c in yearString)
            {
                int i = int.Parse(c.ToString());
                year += yearNumbers[i];
            }
            year += "年";

            // 转换月份
            int monthInt = dateTime.Month;
            if (monthInt == 10)
            {
                month = "十";
            }
            else if (monthInt > 10)
            {
                month = "十" + monthNumbers[monthInt % 10];
            }
            else
            {
                month = monthNumbers[monthInt];
            }
            month += "月";

            // 转换日期
            int dayInt = dateTime.Day;
            if (dayInt <= 31)
            {
                day = dayNumbers[dayInt];
            }
            day += "日";

            return year + month + day;
        }
    }

    public struct DoubleInterval
    {
        public double Start;
        public double End;

        public bool Contains(double value)
        {
            return value > Start && value <= End;
        }
    }
}
